Strapi a opensource headless CMS for developing content rich applications using Javascript.
Nuxt is a framework on top of the Vue progressive JavaScript framework. Along with Vuejs it offers fast development, with minimal bundle size and performance upgrade over other frameworks.
Integrating Strapi using Apollo in Nuxt
Strapi exposes API for each collection types and have corresponding API end points. So graphql can consume it.
Graphql allow us to query data required. May be we not need the entire REST API data. Graphql can installed as on strapi with zero configuration. Once you are ready with strapi configure Apollo using the nuxt module.
Configure @nuxt/apollo
Install the strapi dependency
yarn add --dev @nuxtjs/apollo
also need to configure the nuxt config.
export default {
modules: ['@nuxtjs/apollo',
],
apollo: {
clientConfigs: {
default: {
httpEndpoint: process.env.BACKEND_URL || "http://localhost:1337/graphql",
}
}
},
}
Gql queries ?
Let’s prepare our first Graphql query. In the project add a folder apollo/queries/category/articles-categories.gql with following
query {
categories {
data {
id
attributes {
name
}
}
}
}
Executing Graphql queries in Page component
In the index.vue page or in any page we can execute the query as follows
<script>
import articlesQuery from "~/apollo/queries/categoris/articles-categories";
export default {
data() {
return {
category: {
data: [],
},
};
},
apollo: {
category: {
prefetch: true,
query: articlesQuery,
variables() {
return { id: parseInt(this.$route.params.id) };
},
},
},
};
</script>
- Graphgql :Querying single document in Prismic
- Integrate Hygraph with Svelte, React, Vue
- Integrate Contentful in Vue 3
- Storing and querying data in Gatsby
- How to build a blog using Nuxt 3 and Graphql
- How to build a blog with Solidjs
- Setup Graphql client in Nuxt3
- How to enable Editorjs plugin in Strapi
- How to integrate Strapi-graphql in Nuxt 2
- How to fetch graphql API in Solidjs