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

[graphql-tools/load] loadDocuments different error strategies #4687

Open
Tracked by #5201 ...
n1ru4l opened this issue Aug 31, 2022 · 0 comments
Open
Tracked by #5201 ...

[graphql-tools/load] loadDocuments different error strategies #4687

n1ru4l opened this issue Aug 31, 2022 · 0 comments

Comments

@n1ru4l
Copy link
Collaborator

n1ru4l commented Aug 31, 2022

Is your feature request related to a problem? Please describe.

Currently, if one of the GraphQL documents loaded via loadDocuments is invalid (e.g. raises a parse error), a single GraphQLError instance is thrown.

However, it might be useful to sometimes have:

  • access to all the failed parsing errors
  • access to the successfully parsed documents and the failed parsed documents

Describe the solution you'd like

Introduce different "load error behaviors" that alter the error handling. This could be done by a property that is passed to the loadDocuments function.

Raise first error as it happens (current behaviour)

const documents = await loadDocuments(['packages/**/*.graphql', 'packages/**/*.ts(x)'], {
  loaders: [new GraphQLFileLoader(), new CodeFileLoader()],
  errorBehaviour: 'legacy' // !!! better name recommendations welcome!!!
});

Raise all errors as AggregateError

const documents = await loadDocuments(['packages/**/*.graphql', 'packages/**/*.ts(x)'], {
  loaders: [new GraphQLFileLoader(), new CodeFileLoader()],
  errorBehaviour: 'aggregate'
});

Do not raise an error at all, but instead include error in the return result

const documents = await loadDocuments(['packages/**/*.graphql', 'packages/**/*.ts(x)'], {
  loaders: [new GraphQLFileLoader(), new CodeFileLoader()],
  errorBehaviour: 'ignore'
});

documents[0].document // this is null 
documents[0].error // this is a GraphQLError

Describe alternatives you've considered

So far there is no alternative solution except re-implementing the function from scratch for each use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant