dotansimha / dotansimha/graphql-code-generator
Unable to create custom document loader for glob pattern source
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
I 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`, 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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.