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

Feature Request: Adding resolve method to new schema language #499

Closed
achakravarty opened this issue Sep 22, 2016 · 5 comments
Closed

Feature Request: Adding resolve method to new schema language #499

achakravarty opened this issue Sep 22, 2016 · 5 comments

Comments

@achakravarty
Copy link

I am fairly new to GraphQL and quite like the new schema language. I was just wondering why the resolve method is not a part of the it. It would be really awesome if there was a feature that would allow the resolve functionality to work with the new schema. Thanks

@stubailo
Copy link
Contributor

We have a package for this that we and some other companies have been using in production for a while, graphql-tools.

I think it's exactly what you're looking for, and even supports unions/interfaces, custom scalars, etc.

See an example here: https://github.com/apollostack/graphql-syntax#graphql-tools

Full docs here: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html (although a bit outdated)

See a full example server here: https://github.com/apollostack/GitHunt-API/blob/master/api/schema.js

@helfer
Copy link
Contributor

helfer commented Sep 22, 2016

@achakravarty For more context: the resolvers aren't part of the GraphQL schema language, because they are implementation specific. Resolve functions contain code, which will look different in Python, Scala, Go, etc. The schema language is independent of the implementation.

@achakravarty
Copy link
Author

@helfer Makes sense. But given that, I was wondering whether it would make sense to support a syntax that allows defining resolve methods and binding them separately like it does in grapql-tool as mentioned my @stubailo

For example:

type User {
  name: getName(user: User) : String //here getName is a function that would take a user and return a String.
}

And build a way to attach a resolve method, ideally based on convention eg.

resolvers: {
  User: {
    getName: (user) => { return "Mr." + user.firstName + ' ' + user.lastName; }
  }
}

And finally be able to bind them to the schema as:

schema.buildSchema(`
  type User {
    name: getName(user: User) : String
  }
`)
.withResolvers(resolvers);

@helfer
Copy link
Contributor

helfer commented Sep 23, 2016

@achakravarty yeah, that's basically what graphql-tools does for javascript. It has a function called makeExecutableSchema, which takes a schema and resolve functions, and then returns an executable schema. I'm sure this could easily be built for other languages as well.

@achakravarty
Copy link
Author

@helfer Cheers! Will refer that then. You can close this issue.

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