How to import GraphQL queries?
See original GitHub issueHi, is it possible to import queries instead of write them directly into the HTTP request? something like:
import productsQuery from '~/queries/products.gql'
async asyncData({ $strapi }) {
const products = await $strapi.graphql({ query: productsQuery })
return { products }
}
instead of the documented method:
async asyncData({ $strapi }) {
await $strapi.graphql({
query: `
query {
products {
...
}
}
`
});
}
In my case I’m getting HTTPError processTicksAndRejections
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Loading queries with Webpack - Apollo GraphQL Docs
You can load GraphQL queries over .graphql files using Webpack. ... query CurrentUserForLayout { ... import { graphql } from '@apollo/react-hoc';.
Read more >How to import GraphQL query? - Stack Overflow
To import GraphQL queries you need a specific loader. When you are using webpack you can for example use graphql-tag/loader from graphql-tag ...
Read more >Getting Started with GraphQL, Part 1: Importing and Querying ...
Steps to get started · 1. GraphQL schema definition file · 2. Create a database using Fauna Shell and a provision a key...
Read more >The graphql module exports a core subset of GraphQL ...
The graphql module exports a core subset of GraphQL functionality for creation of GraphQL type systems and servers. import { graphql } from...
Read more >Loading .graphql Files - Create React App
import · query User { · user(id: 5) { · lastName ·...UserEntry1 · } · }
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nonlinearcom No need for graphql-tag package, just use this example:
This works for me
Anyone feels like opening a PR for the docs to add the usage with
gql
on https://strapi.nuxtjs.org/strapi#graphqldata ?