cjoudrey / graphql-schema-linter

Validate GraphQL schema definitions against a set of rules
MIT License
694 stars 62 forks source link

Load schema asynchronously #223

Closed dnerdy closed 4 years ago

dnerdy commented 4 years ago

This PR makes schema loading asynchonous so that a schema can be read from stdin when the input source might block.

The aync commit separates schema loading from the config. The schema is now passed to the config as an argument. Loading of the linter config file has also been pulled out of the Configuration class because that config can incluence how the schema is loaded.

The Configuration getSchema and getSchemaSourceMap functions have been kept intact since rules may use these functions.

I've verified that the test.js file in #211 successfully runs with this change.

Fixes #211.

Note that this PR also updates babel and uses preset-env so that translations aren't used for features already supported by node. Async schema loading uses async/await, and async/await have been supported in node since version 7.6.0[1].

The use of the yearly presets has been deprecated[2].

I've set the node target to 9.4 since the stream "data" and "end" events (which will be used to read from stdin) were added in that version[3].

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function [2] https://babeljs.io/docs/en/babel-preset-es2015/ [3] https://nodejs.org/api/stream.html#stream_event_data

dnerdy commented 4 years ago

Thanks a lot for the contribution!

For sure! Your high quality tests make it easy. 😄