-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hijack and make it work how I would imagine it #1
base: main
Are you sure you want to change the base?
Conversation
return { | ||
- document: graphql.concatAST(sources.map(source => graphql.parse(source, options))), | ||
+ document, | ||
+ rawSDL: sources.map(source => source.body).join(`\n#-#\n`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rawSDL is used for building the operation string to Type mapping. Since multiple gql
calls are merged into a single document \n#-#\n
is used for separating them later.
If we don't provide rawSDL
at all, something very weird is happening as it is tried to be auto-generated somewhere and we end up with something weird similar to this: ardatan/graphql-tools#3124
For three gql
calls within a single document rawSDL
equals to the following string
[Object object]\n\n[Object object]\n\n[Object object]
- ignore: Object.keys(config.generates).map(p => path.join(process.cwd(), p)), | ||
+ ignore: Object.keys(config.generates).map(p => { | ||
+ let ignorePath = path.join(process.cwd(), p) | ||
+ if (ignorePath.endsWith("**/*") === false) { | ||
+ ignorePath += "**/*" | ||
+ } | ||
+ return ignorePath | ||
+ }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an exact idea what is going on here and this patch probably breaks other stuff. I noticed that the following codegen config:
generates:
./demo/gql/:
preset: ./lib/preset.js
plugins: [./lib/plugin.js]
Would result in the following error:
Error: unable to find loader for glob "/Users/laurinquast/projects/graphql-typescript-integration/demo/gql/"
at addGlobsToLoaders (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/index.js
:295:19)
at collectPathsFromGlobs (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/inde
x.js:331:5)
at collectSources (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/index.js:21
6:23)
at loadTypedefs (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/index.js:609:
21)
at loadDocuments (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-codegen/cli/bin.js:515:
31)
at /Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-codegen/cli/bin.js:916:55
at Task.task (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-codegen/cli/bin.js:761:17)
Error: unable to find loader for glob "/Users/laurinquast/projects/graphql-typescript-integration/demo/gql/"
at addGlobsToLoaders (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/index.js
:295:19)
at collectPathsFromGlobs (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/inde
x.js:331:5)
at collectSources (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/index.js:21
6:23)
at loadTypedefs (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-tools/load/index.js:609:
21)
at loadDocuments (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-codegen/cli/bin.js:515:
31)
at /Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-codegen/cli/bin.js:916:55
at Task.task (/Users/laurinquast/projects/graphql-typescript-integration/node_modules/@graphql-codegen/cli/bin.js:761:17)
I dug into it and it seems that the folder is not properly ignored because the string must be a glob pattern. So I simply added it there.
const expandSources = (sources: Array<Source>): Array<Source> => { | ||
const expandedSources: Array<Source> = []; | ||
for (const source of sources) { | ||
const document = source.document!; | ||
const rawSDL = source.rawSDL!; | ||
const operationSDL = rawSDL.split(`\n#-#\n`); | ||
operationSDL.forEach((rawSDL, index) => { | ||
expandedSources.push({ | ||
document: { | ||
kind: "Document", | ||
definitions: [document.definitions[index]], | ||
}, | ||
rawSDL, | ||
location: source.location, | ||
}); | ||
}); | ||
} | ||
return expandedSources; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we split our operations that got concatenated into a single string via CodeFileLoader into back into single operations. SO we can properly create the operations raw string -> type document node mapping
No description provided.