Skip to content
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

Allow configuration of @graphql-tools loaders #360

Closed
GuiHash opened this issue Oct 23, 2021 · 3 comments · Fixed by #365
Closed

Allow configuration of @graphql-tools loaders #360

GuiHash opened this issue Oct 23, 2021 · 3 comments · Fixed by #365
Assignees
Labels
enhancement New feature or request

Comments

@GuiHash
Copy link
Contributor

GuiHash commented Oct 23, 2021

Currently, it is not possible to add a configuration to @graphql-tools loaders.

It would be interesting to be able to do it in order to configure url-loader with headers (https://www.graphql-tools.com/docs/schema-loading#url-loader)

If you are interested I can submit a PR, if we agree on how to pass these parameters without creating breaking changes on the configuration of your plugin to load the @graphql-tools loaders

@GuiHash GuiHash added the enhancement New feature or request label Oct 23, 2021
@edno
Copy link
Member

edno commented Oct 23, 2021

Hi @GuiHash

That's definitively something I have missed when refactoring the schema loaders. Much needed.
I don't see a way to do it without a change in the code. But, a quick way to do it would be to add an optional parameter loaderOptions (default = undefined) that accepts any object type (JSON format), then we can pass it directly to loadSchema() in generateDocFromSchema():

const schema = await loadSchema(
  schemaLocation,
  { loaders: getDocumentLoaders(loaders), }, 
  loaderOptions
);

And enhancing the plugin config loaders format to:

type className = string; // UrlLoader

type moduleName = string; // "@graphql-tools/url-loader"
+ type moduleOptions = { [option: string]: any };
+ type module = { 
+   module: moduleName, 
+   options: moduleOptions | undefined 
+ }

type loaders = {
-  [className: className]: moduleName
+  [className: className]: moduleName | module
}

Please go ahead and submit a PR 🚀

@edno
Copy link
Member

edno commented Oct 24, 2021

Released in 1.5.3

@chmanie
Copy link
Contributor

chmanie commented Apr 5, 2023

Hey! I'm sorry to revive this, but I don't really understand the implementation there. It seems all the options passed are moved to an object called loaderOptions which is then passed as is into the options that the graphql-tools loader takes. This is how the options look like then:

{
  loaders: [ UrlLoader {} ],
  loaderOptions: { headers: { 'x-api-key': 'xxx' } },
  filterKinds: [ 'OperationDefinition', 'FragmentDefinition' ],
  ignore: [],
  cache: {},
  cwd: '/home/chris/dev/colony/docs',
  sort: true
}

Though I think the loaderOptions need to be merged into this object, not included. Or am I doing anything horribly wrong?

EDIT: It might be a regression. Here's the original PR which merges the loaderOptions:

https://github.com/GuiHash/graphql-markdown/blob/e05985ef57b060dd785db3a02258276247beadc4/src/lib/generator.js#L25-L28

Here's the current code which just passes it in:

const loaders = getDocumentLoaders(loadersList);
const schema = await loadSchema(schemaLocation, loaders);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

3 participants