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

Cacheable schema manipulation via directives #140

Merged
merged 79 commits into from
Jun 20, 2018
Merged

Cacheable schema manipulation via directives #140

merged 79 commits into from
Jun 20, 2018

Conversation

spawnia
Copy link
Collaborator

@spawnia spawnia commented Jun 8, 2018

This PR rebuilds how Lighthouse deals with schema manipulation.

Reasoning

Directives can now implement an Interface that marks them as schema-manipulating. This manipulation is executed directly on the AST. This has multiple benefits:

  • Schema manipulation is very explicit, no more surprises!
  • The final AST is completely cached when in production
  • Directives are now able to easily add new types, fields or arguments - which can take full advantage of directives themselves!

In the spirit of 'schema-first', this also enables full utilization of the SDL.
The final schema can be validated and printed before using it in production.
Users can use the output for documentation, mocking or static query analysis.

This also opens the door for more complex schema manipulation. The features proposed in #131 and #84 would greatly benefit from this.

Bugfixes

Coincidentally, i found and fixed a bug that prevented middlewares being applied in some cases, this might resolve the Issues #134 and #121

Backwards compatibility

I made sure to keep most of the tests as they were before to ensure we do not break existing use-cases. While the inner workings where changed quite a bit, the functionality of the directives should be the same as before.

Caching now uses Laravels Cache Facade. To enable caching, a new configuration option was added. Users that have the previous configuration will not get caching for their AST but can easily update their config to enable caching.

Breaking changes

Custom directives will have to be changed. All directives have to implement a common Interface. Schema manipulation should only happen by implementing the respective Manipulator interface: ManipulateType, ManipulateField and ManipulateArg

Some internal classes were shifted around so users that reach directly into our source might have to change their code as well. This should not be a big issue as we haven't formally specified a public API yet.

spawnia and others added 30 commits May 30, 2018 09:13
…ator-directives

# Conflicts:
#	docker-compose.yml
#	src/Schema/Directives/Fields/PaginateDirective.php
#	src/Schema/MiddlewareManager.php
#	src/Schema/SchemaBuilder.php
#	src/Schema/Utils/DocumentAST.php
#	src/Support/Contracts/SchemaGenerator.php
#	src/Support/Traits/CreatesPaginators.php
…e interface for FieldManipulator and NodeManipulator
The node field must only be added if it is implemented by another type, otherwise the schema is not valid
…ator-directives

# Conflicts:
#	src/Schema/CacheManager.php
#	src/Schema/SchemaBuilder.php
spawnia added 10 commits June 14, 2018 17:18
- This is because it is often useful to only run Unit tests first, since the Integration tests almost all fail if a single mistake happens
- Found & fixed a bug where the static attributes on DocumentValidator, set in SecurityTest, influence the execution of all other tests
- This actually validates that test queries are valid
- Found & Fixed a few test queries that were invalid
- Properly indent all schema definitions and queries
- Clean up whitespace
- Fix some Doc Blocks
- Add comments
- Remove unused methods
@hailwood
Copy link
Contributor

image

@spawnia: Don't mind me, I'm just rewriting Lighthouse

Monumental effort, exciting stuff here!

@chrissm79 chrissm79 merged commit 5d43d1d into nuwave:master Jun 20, 2018
@spawnia spawnia deleted the generator-directives branch June 20, 2018 11:16
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

Successfully merging this pull request may close these issues.

4 participants