"Error: Query cannot be executed. The request does not include a query neither in the body nor in the query string" #7291
-
Strange issue. Can't find anything with google so I will try here. The following setup throws the error in the title. I have tested the query, it works just fine in Postman and GraphiQL
query getAllUsers {
userCollection {
items {
name
birthdate
}
}
}
schema:
- https://graphql.contentful.com/content/v1/spaces/<id>:
headers:
Authorization: 'Bearer <token>'
documents: './src/**/*.graphql'
generates:
./src/queries/generated.tsx:
plugins:
- typescript
- typescript-operations
- typescript-react-query
config:
exposeFetcher: true
exposeQueryKeys: true
fetcher:
endpoint: 'https://graphql.contentful.com/content/v1/spaces/<id>'
fetchParams:
headers:
Authorization: 'Bearer <token>' In the component: const Page: i.NextPageComponent = () => {
const { data } = useGetAllUsersQuery();
...
} This is the request payload that I can see in my browser terminal. Is this right? {"query":"\n query getAllUsers {\n userCollection {\n items {\n name\n birthdate\n }\n }\n}\n "} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I found the issue, and I will leave this discussion for anyone else experiencing this issue in the future. I forgot to add the content-type header. With this codegen file it works schema:
- https://graphql.contentful.com/content/v1/spaces/<id>:
headers:
Authorization: 'Bearer <token>'
documents: './src/**/*.graphql'
generates:
./src/queries/generated.tsx:
plugins:
- typescript
- typescript-operations
- typescript-react-query
config:
exposeFetcher: true
exposeQueryKeys: true
fetcher:
endpoint: 'https://graphql.contentful.com/content/v1/spaces/<id>'
fetchParams:
headers:
Content-Type: 'application/json'
Authorization: 'Bearer <token>' |
Beta Was this translation helpful? Give feedback.
-
Had too many problems configuring this, here it is what I've done:
Create file 'codegen.yaml' with this config:
Add this script to 'package.json':
Finally: Hope this helps someone. |
Beta Was this translation helpful? Give feedback.
I found the issue, and I will leave this discussion for anyone else experiencing this issue in the future.
I forgot to add the content-type header.
With this codegen file it works