Unable to create custom document loader for glob pattern source
See original GitHub issueI am trying to write my own document loader to facilitate the usage of the @export
directive from Apollo Client. I found several issues (#3939 & #2771) (even a PR #3886) that contain bits and pieces for the solution, but I figured I’d require a custom document loader because I need to filter out some variable definition requirements to prevent syntax errors.
I am now running into the issue that the custom document loader functionality provided by GraphQL Codegen (and if I followed the code trail correctly, it’s actually the custom loader functionality of @graphql-tools/load
) is expecting a single Source
, string
or GraphQLSchema
return value. This is a bit hard when I am trying to facilitate a loader for a glob pattern. This will inherently return a Source[]
or string[]
.
Also, I literally tried to use the loadDocuments
function from @graphql-tools/load
(I noticed the arguments given to the loader are exactly the same as the ones loadDocuments
expects.) This’ll return an Array<Source>
, and even just returning a single Source
I keep getting the following error:
Error:
Unable to find any GraphQL type definitions for the following pointers:
- **/*.graphql
at prepareResult (/workspace/node_modules/@graphql-tools/load/index.js:507:15)
at loadTypedefs (/workspace/node_modules/@graphql-tools/load/index.js:473:12)
at async loadDocuments (/workspace/node_modules/@graphql-codegen/cli/bin.js:540:31)
at async /workspace/node_modules/@graphql-codegen/cli/bin.js:944:55
at async Task.task (/workspace/node_modules/@graphql-codegen/cli/bin.js:789:17)
I hope I am doing it wrong, so I’d love a working example of a custom document loader for a glob pattern, but I am afraid it’s not supported by @graphql-tools/load
(atleast not for a CustomLoader
). If this is the case, what’s the expected path to take from here?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:16 (1 by maintainers)
Hi @B2o5T I’ll create it this weekend
It seems to me like custom loaders just got skipped over in https://github.com/ardatan/graphql-tools/pull/3157. Would it be sufficient to just change the lines here to add a check if the custom loader returned an array of sources, and if so, add all the sources to the list? Then custom loaders could function the same as the rest of the loaders (fallback loaders, if I’m reading the code correctly).