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

Making sure the input data for resolvers is consistent #38

Closed
charypar opened this issue Jul 10, 2015 · 3 comments
Closed

Making sure the input data for resolvers is consistent #38

charypar opened this issue Jul 10, 2015 · 3 comments

Comments

@charypar
Copy link

This is not really as much a problem as a question about practices. Playing with GraphQL I realised that argument resolutions rely on types always getting the same data structure from the parent resolver (unless you want to branch the logic in them).

Is there any clever way to ensure this? So for instance wherever I define an attribute of the Image type, I can make sure a resolver for that attribute eventually returns a data structure which attribute resolvers on Image can handle.

@leebyron
Copy link
Contributor

Great question. This is something I would say is currently not easy to do in the JS reference impl but probably should be. I'll leave this open to track it.

In our PHP implementation in production at Facebook, we have a function that each type defines that simply checks to ensure the produced value correctly fits the type expected (returns boolean), so that resolver functions for the sub-fields can be written with more confidence.

@charypar
Copy link
Author

So would a potential solution like the Facebook one look something like this?

const Thing = new GraphQLObjectType({
  name: "Thing",
  description: "It's a 3D thing!",
  validate: (it) => (it.width && it.height && it.depth),
  fields: ...
});

@leebyron
Copy link
Contributor

Yes, graphql-js has a function like this currently called isTypeOf, I just need to wire it up in this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants