Comments (9)
You mean generate a .switft
file from a graphql schema?
from graphql.
No I mean a .graphql file where I can specify the schema like in code.
from graphql.
how are you going to define the resolvers with a .graphql
file?
from graphql.
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
from graphql.
@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.
from graphql.
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:
type Query {
user: User
}
type User {
name: String
}
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: query { user { name } }
the library will look for a method on the query resolver that maps to the user
-field (simply by being called user()
or getUser()
). It calls that method, takes its return value (for example an instance of a class called User
), and checks if it has a method called name()
or getName()
on it. If it does, it calls that method and outputs its return value. If it doesn't, it then looks for any resolvers that can take a User
instance and that have a method called name
or getName
, and calls those instead.
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.
from graphql.
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.
from graphql.
Also, I believe such a high level feature belongs to a higher level framework. Maybe github.com/graphqlswift/graphiti or another standalone framework.
from graphql.
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.
Again thank you for the help.
from graphql.
Related Issues (20)
- AsyncThrowingStream.mapStream produces leaks and loses error during transformation HOT 1
- Custom Schema Directives? HOT 1
- Disabling introspection e.g. in production HOT 6
- GraphQLError missing `extensions` HOT 2
- client library
- Create queries/mutations from GraphQL schema
- Upgrade Swift-NIO dependency to 2.0.0+ HOT 1
- Preserve result order HOT 3
- False positive with no unused variable rule HOT 3
- GraphQL parser does not support optional `Description`s.
- GraphQL doesn't support "Blockstrings" which are often used in Descriptions.
- GraphQL parser does not seem to have support for the '&' character HOT 2
- intValue() always throws exception HOT 1
- 0 default value for argument is interpreted as false and can not be used HOT 2
- Is this library single-threaded only? HOT 3
- GraphQL doesn't compile on Linux Swift 5.4 HOT 5
- Top level fields in mutations should execute in SERIES not parallel HOT 2
- Is async/await supported?
- Error "Must be leaf type" in listValue HOT 1
- Is there a way to validate a document with custom validation rules? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql.