GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
531 stars 66 forks source link

Schema File #19

Open alexsteinerde opened 6 years ago

alexsteinerde commented 6 years ago

Hey, 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

daviskoh commented 5 years ago

Would be interested in something like this as well.

Personally, I think that a good flow would be to parse a schema.graphql file(s) and codegen a usable Graphiti Schema type in Swift similar to how projects like apollo-tooling for clientside Swift and gqlgen for Go do. Resolver handlers would be stubbed out with proper closure arguments that consume generated Swift types as well.

What I've seen from libs that map GraphQL to static langs like Swift and Go that have granular types (like a uint32) is that such mapping may need some extra implementation logic. Maybe using something Schema Directives, though I'm not sold on it. For example:

Type Example {
  field: Int @Swift(type: "UInt32")
}

☹️

Ultimately, it would obviously be the generated Swift code itself that is consumed by something like a server and not the schema.graphql file(s).

What I am talking about would be a CLI and may be a separate project. 🤔🤷‍♂️

johndpope commented 5 years ago

This could be quite some work - but I've created a graphql file parser https://github.com/johndpope/antlr-graphql-playground

To use this - you need to get head around antlr / lexars / parsers. (this is something I'm yet to master - although with enough perserverance this is definitely the right path.)

Fortunately - someone's already done some hard yards here. This graphql-java repo is very polished - but there maybe older commits with some bare bones code that could be decyphered. I've used the same g4 grammar files. https://github.com/graphql-java/graphql-java

I may take another look at this if there's interest.

Screen Shot 2019-09-05 at 4 00 37 pm

UPDATE It maybe simpler to use something like this to parse graphql file https://github.com/prisma/vscode-graphql/blob/master/grammars/graphql.json

alexsteinerde commented 4 years ago

Technically it is not possible to scan a schema.graphql file and use reflections to access necessary resolvers, types, etc. yet. Swift doesn't allow this in it's current implementation. But I think @daviskoh code-gen idea is the best way to go if we want to have a schema file as the single source of truth, I think.