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

Add Query as a Query #15

Closed
Zn4rK opened this issue Feb 12, 2017 · 0 comments
Closed

Add Query as a Query #15

Zn4rK opened this issue Feb 12, 2017 · 0 comments

Comments

@Zn4rK
Copy link
Contributor

Zn4rK commented Feb 12, 2017

So this is not really an issue, but I think it's worth discussing and I want it documented so that other people might find a use for it.

The background to this discussion is this issue. The current version of Relay (0.10) doesn't support root fields/queries to be arrays. In the linked issue above they suggest a workaround until Relay 2 is released. An updated version of the workaround has been suggested in this issue: lucasbento/graphql-pokemon#1

I don't think we should build support for this, since Relay 2 is coming, but the easiest way to add this to a project would be to extend GraphQL - since it's registered through Laravel's service container, and override the buildSchema()-method:

Nuwave\Lighthouse\GraphQL

public function buildSchema() { 

	...
	
	$fields = $queryType->config['fields'];
	$fields['query'] = [
	    'args' => [],
	    'type' => $queryType,
	    'resolve' => function() {
	        return true; // we need to have a closure that returns something
	    }
	];
	$queryType->config['fields'] = $fields;
	
	...
	
	return new Schema([
	            'query' => $queryType,
	            'mutation' => $mutationType,
	            'types' => $this->typesWithInterfaces->all(),
	        ]);

This is a hack(!) and probably shouldn't be used in production.

One could get away with doing something similar in their extension if they first call the parent on the overridden method (buildSchema()) and then get the mutations, queries and types from the generated Schema, and then instantiate a new Schema.

This is not recommended, since this package will most likely change.

If anyone has any suggestions on how (and why) support for this should be implemented for real, please, leave a comment!

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