Reputation: 405
After I run command yarn gen
it is giving me this error :
Something went wrong Failed to load schema for "graphql/" Failed to load schema from http://localhost:1337/graphql:
fetch failed TypeError: fetch failed at Object.processResponse (node:internal/deps/undici/undici:5570:34) at node:internal/deps/undici/undici:5896:42 at node:internal/process/task_queues:140:7 at AsyncResource.runInAsyncScope (node:async_hooks:202:9) at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
GraphQL Code Generator supports:
- ES Modules and CommonJS exports (export as default or named export "schema")
- Introspection JSON File
- URL of GraphQL endpoint
- Multiple files with type definitions (glob expression)
- String in config file
Try to use one of above options and run codegen again.
here is my homepage.graphql
query HomePage {
homePage {
data {
attributes {
sections {
... on ComponentCommonHeader {
id
Text
ButtonText
ButtonLink
}
... on ComponentCommonCarousel {
id
Item
}
... on ComponentCommonTwoColumnBlock {
id
TitleText
Description
ButtonText
ButtonUrl
ImagePosition
Image
}
}
}
}
}
}
and here is my graphql.config.yml:
overwrite: true
schema:
- http://localhost:1337/graphql
documents: "graphql/**/*.graphql"
generates:
graphql/types.tsx:
plugins:
- "typescript"
graphql/:
preset: near-operation-file
presetConfig:
extension: .generated.tsx
baseTypesPath: types.ts
plugins:
- "typescript-operations"
- "typescript-react-apollo"
config:
withHooks: true
Upvotes: 0
Views: 1928
Reputation: 92
I ran into this and fixed it by replacing localhost
with 127.0.0.1
. Other solution that you may want to try is to delete node_modules
and package-lock.json
and to reinstall dependencies.
Upvotes: 0