graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

`loadDocuments` Documentation or Type Error

Open shellscape opened this issue 3 years ago • 1 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [x] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

The documentation here: https://www.graphql-tools.com/docs/documents-loading#usage states that one can call loadDocuments via:

loadDocuments('query { f }')

However, the typings that ship for the function are:

export declare function loadTypedefs<AdditionalConfig = Record<string, unknown>>(pointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], options: LoadTypedefsOptions<Partial<AdditionalConfig>>): Promise<Source[]>;

As shown, options is not optional.

Attempting to call that without an options object that specified a loaders property results in:

@graphql-tools/load/cjs/load-typedefs/load-file.js:52
        for (const loader of options.loaders) {
                                     ^
TypeError: options.loaders is not iterable

That suggests the documentation is incorrect, and that there is no means to load that string as-is.

To Reproduce Steps to reproduce the behavior:

  • Attempt to call the function within a TypeScript app

Expected behavior

Expectation was that the documentation was correct and matched the shipped typings.

Environment:

  • OS: Mac
  • @graphql-tools/...: load@^7.7.1
  • NodeJS: 14.19.0

Additional context

TypeScript v4.7.4

shellscape avatar Aug 04 '22 12:08 shellscape

Additionally, that page has a section which states:

For notes on typescript, refer to loaders

That links to https://www.graphql-tools.com/docs/loaders, which is 404. It appears the correct link should be https://www.graphql-tools.com/docs/schema-loading#loaders

shellscape avatar Aug 04 '22 12:08 shellscape