-
Notifications
You must be signed in to change notification settings - Fork 70
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
Schema File #31
Comments
You mean generate a |
No I mean a .graphql file where I can specify the schema like in code. |
how are you going to define the resolvers with a |
I don't know if this can be done in Swift in the same way, but with the Java implementation of GraphQL, you can just provide the schema file, and the library will automatically map the fields in the schema to the corresponding fields in the data model, or to appropriately named resolver functions if no fields are found: https://github.com/graphql-java/graphql-java-tools#resolvers-and-data-classes |
@Hikaru755 This would be possible in Java by creating classes out of thin air? If so, Swift doesn't allow this. It's reflection/introspection/dynamic capabilities are very limited so far. |
It doesn't create classes on the fly, you still have to define all classes and resolvers for the types in the schema yourself (or generate them via other means). It's just the mapping between them and the schema fields that happens automatically. Basically, if you can get a list of methods of an object and call them dynamically by their name it should be possible. Let me explain by example, if we have the following GraphQL schema file:
In Java, when you first configure your GraphQL endpoint, you have to pass that schema plus a QueryResolver to the library, as well as any additional resolvers you need. If a request comes in, like this: It just lets you define your schema in a language-agnostic way, and uses it to choose the correct resolver functions by naming convention, instead of having to verbosely build the schema in your implemenation logic and attach the resolvers to the fields manually. |
Got it! Thanks for the thorough explanation. I believe it's possible to implement that feature in the way you mentioned. Currently I don't have as much time as I want to implement this. If anyone is interested I can give directions. |
Also, I believe such a high level feature belongs to a higher level framework. Maybe github.com/graphqlswift/graphiti or another standalone framework. |
That sounds logic to me and I have not found Grafphiti before. So thanks for the link. I will create an issue there and close it here. |
It would be great to have the ability to provide a schema file to the server and start it with the file content.
Or is this already possible just not listed in the readme?
Thanks
Alex
The text was updated successfully, but these errors were encountered: