Fetch teekyuu with graphql request

This commit is contained in:
Hydroxycarbamide 2022-05-15 15:35:02 +02:00
parent b4edb9d8f8
commit 03e63ff580
7 changed files with 1238 additions and 8 deletions

1126
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,11 @@
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/vue-fontawesome": "^3.0.0-5",
"vue": "^3.2.33"
"@vue/apollo-composable": "^4.0.0-alpha.17",
"apollo-boost": "^0.4.9",
"graphql": "^15.8.0",
"vue": "^3.2.33",
"vue-apollo": "^3.1.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.3.1",

View file

@ -1,6 +1,7 @@
<script setup>
const props = defineProps({
url: String,
title: String,
description: String
})
@ -9,10 +10,10 @@ const props = defineProps({
<template>
<div class="rounded-xl overflow-hidden bg-white mx-auto max-w-md shadow-xl md:max-w-2">
<div class="rounded-xl overflow-hidden bg-white mx-auto max-w-md shadow-md hover:shadow-xl transition-shadow md:max-w-2">
<div class="md:flex">
<div class="md:shrink-0">
<img class="h-48 w-full object-cover md:h-full md:w-48" src="../assets/paripi-koumei.png">
<img class="h-48 w-full object-cover md:h-full md:w-48" :src="url">
</div>
<div class="p-8">
<a class="block mt-1 text-lg leading-tight font-medium text-black hover:underline tracking-wide">

View file

@ -1,8 +1,49 @@
<script setup>
<script>
import Card from './Card.vue';
import query from '../gql/anime';
import { useQuery } from "@vue/apollo-composable";
import { watch } from 'vue';
export default {
data() {
return {
id: 1,
title: null,
description: null,
url: null
}
},
methods: {
async fetchAnime() {
const variables = {
id: 15125
}
this.url = null;
const { result } = useQuery(query, variables);
watch(result, value => {
this.url = value.Media.coverImage.large;
this.title = value.Media.title.english;
this.description = value.Media.description;
});
}
},
mounted() {
this.fetchAnime();
},
components: {
Card
}
}
</script>
<template>
<Card title="My Product" description="My description" />
<div>
<Card :title="title" :description="description" :url="url" />
</div>
</template>

View file

@ -0,0 +1,26 @@
<script setup>
import query from '../gql/anime';
import { useQuery } from "@vue/apollo-composable";
import { watch } from 'vue';
const variables = {
id: 15125
}
function FetchParipiKoumei() {
const { result, loading, error } = useQuery(query, variables);
return result.value;
}
function onClick() {
const result = FetchParipiKoumei();
watch(result, value => {
console.log(value);
})
}
</script>
<template>
<button class="shadow-md p-2 rounded-full bg-blue-500 text-white hover:shadow-blue-500 shadow-blue-200 transition-shadow" @click="onClick">Fetch</button>
</template>

18
src/gql/anime.js Normal file
View file

@ -0,0 +1,18 @@
import { gql } from "apollo-boost";
export default gql`
query ($id: Int) { # Define which variables will be used in the query (id)
Media (id: $id, type: ANIME) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query)
id
title {
romaji
english
native
}
description (asHtml: false)
coverImage {
large
}
}
}
`;

View file

@ -14,10 +14,26 @@ library.add(faFire);
library.add(faPlus);
library.add(faPoo);
import { createApp } from 'vue'
import ApolloClient from "apollo-boost";
import { DefaultApolloClient } from "@vue/apollo-composable";
const apolloClient = new ApolloClient({
uri: `https://graphql.anilist.co/`,
});
import { createApp, provide, h } from 'vue'
import App from './App.vue'
import './index.css'
import { provideApolloClient } from "@vue/apollo-composable";
createApp(App)
provideApolloClient(apolloClient)
createApp({
setup () {
provide(DefaultApolloClient, apolloClient)
},
render: () => h(App),
})
.component("font-awesome-icon", FontAwesomeIcon)
.mount('#app');