graphql-tools
graphql-tools copied to clipboard
[graphql-tools/load] `loadDocuments` different error strategies
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.