question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to create custom document loader for glob pattern source

See original GitHub issue

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<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:open
  • Created 2 years ago
  • Reactions:5
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
JuroOraveccommented, Feb 9, 2022

Hi @B2o5T I’ll create it this weekend

2reactions
abrennekecommented, Oct 6, 2021

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

documents field - GraphQL Code Generator
Custom Document Loader ​​ Suppose your schema has a different or complicated way of loading. In that case, you can specify a custom...
Read more >
Dependency resolution - Parcel
As Parcel builds your source code, it discovers dependencies, which allow code to be broken into separate files and reused in multiple places....
Read more >
Configuration options | Yarn - Package Manager
List of all the configuration option for Yarn (yarnrc files) ... "origin/master" ... Selects exactly one message that must match the given glob...
Read more >
What is Auto Loader? | Databricks on AWS
Auto Loader can load data files from AWS S3 ( s3:// ), Azure Data Lake ... file storage, the cloudFiles source automatically processes...
Read more >
Source Files and Compilation - Cython's Documentation
The cythonize command accepts multiple source files and glob patterns like ... To do this, you can provide a custom function create_extension to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found