Giter Club home page Giter Club logo

Comments (9)

paulofaria avatar paulofaria commented on May 17, 2024

You mean generate a .switft file from a graphql schema?

from graphql.

alexsteinerde avatar alexsteinerde commented on May 17, 2024

No I mean a .graphql file where I can specify the schema like in code.

from graphql.

paulofaria avatar paulofaria commented on May 17, 2024

how are you going to define the resolvers with a .graphql file?

from graphql.

roschlau avatar roschlau commented on May 17, 2024

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.

paulofaria avatar paulofaria commented on May 17, 2024

@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.

roschlau avatar roschlau commented on May 17, 2024

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.

paulofaria avatar paulofaria commented on May 17, 2024

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.

paulofaria avatar paulofaria commented on May 17, 2024

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.

alexsteinerde avatar alexsteinerde commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.