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

Federated service doesn't always need a Query type #2164

Closed
erikhh opened this issue Jan 18, 2021 · 5 comments
Closed

Federated service doesn't always need a Query type #2164

erikhh opened this issue Jan 18, 2021 · 5 comments

Comments

@erikhh
Copy link

erikhh commented Jan 18, 2021

I'm using graphql-java in combination with Apollo federation-jvm (0.5.0). The new schema validation in 16.1 seems to break one of my services.
When it starts I get the errror: "Query" must define one or more fields.

Under 15.0 the exact same schema definition works fine.

This service only adds additional fields to existing types. It has nothing useful to add to the top level Query object. I would prefer not to add some artificial dummy field to the Query type just to please the graphql-java validation.

Is there a chance the validation might be loosened a little at this point? Or can I manually disable/ignore/skip it somewhere?

@andimarek
Copy link
Member

I am sorry to hear that it doesn't work, but this projects goal is to support the official GraphQL spec.

We don't have the capacity to maintain derivations from the spec, therefore we don't support non spec features in general.

I hope you can understand.

Best,
Andi

@tinnou
Copy link
Contributor

tinnou commented Jan 18, 2021

This issue is closely related to the effort of updating apollo federation jvm to the latest graphql-java version (16.1).

While this would go beyond the scope of just supporting the GraphQL spec, it does make lives easier when using graphql-java with Apollo Federation.

As suggested, we could expose a way to merely skip certain validation rules and/or replace with a different set of rules, this feature would be provided "at your own risk".

@bbakerman
Copy link
Member

Since we are talking about hacking around the standard, you can do this.

You can define a field x : int to make the validation happen.

Then you can use graphql.schema.visibility.GraphqlFieldVisibility to remove the field dynamically at runtime

@andimarek
Copy link
Member

I am reopening it to clarify some details:

As outlined above this projects goal is not to support non standard spec, but maybe there is an alternative to make this useable without breaking spec:

@erikhh @tinnou Can you help me understand better why apollo federation needs an empty Query type? Thanks

@andimarek andimarek reopened this Jan 19, 2021
@erikhh
Copy link
Author

erikhh commented Jan 19, 2021

I am sorry, my issue could have been described in better detail. And I was also maybe a bit beside the actual point. My sincere apologies.

In my project the schema file does not specify a Query type. But after the schema has been parsed the federation-jvm library dynamicaly adds a Query type like this one:

type Query {
  _service: _Service
  _entities(representations: [_Any!]!): [_Entity]!
}

Which makes the end result spec compliant but the validation takes place during the parsing of the schema file now, and this makes it fail before federation-jvm can work it's magic.

I have solved this by adding this bit to the schema file.

type Query {
  _service: _Service
}

type _Service {
  sdl: String!
}

This makes the schema parser happy and federation-jvm is going to add it anyway. It's probably even a good thing to make the schema file more complete.

Thanks for your time and input everyone!

@erikhh erikhh closed this as completed Jan 19, 2021
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

4 participants