Skip to content

Is there some good way to make GraphQLFieldResolveFn<SOURCET, VARIABLET> <- like this? #393

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

Closed
iamchenxin opened this issue May 29, 2016 · 3 comments

Comments

@iamchenxin
Copy link
Contributor

iamchenxin commented May 29, 2016

At now , GraphQLFieldResolveFn's definition is like this,
which source: mixed and args: {[argName: string]: mixed}

type GraphQLFieldResolveFn = (
  source: mixed,
  args: {[argName: string]: mixed},
  context: mixed,
  info: GraphQLResolveInfo
) => mixed

But the Relay use a subset of those data ,In Relay, the resolver is assumed to something like this:

type GraphQLFieldResolveFn = (
  source: Object,
  args: {input: Object},
  context: mixed,
  info: GraphQLResolveInfo
) => mixed

So when Graphql-Relay make a static flow type check with a flow typed Graphql ,this will make a conflict (mixed -> Object).
I find source type are begin with execute() in execute.js .But execute() should be called by a GraphQL server (like express-grapgql), so is it wired to use Template to make ResolveFn to accept a new type which used by end-user (like relay-graph)?
Also causeof the source separate many place in graphql's source code . and at now seems sometimes if Flow can not resolve Template, it will set the Template to any Type. Use a wild-separated template makes me a little nervous.
Is there some good way to make the GraphQLFieldResolveFn accept end-user's Flow type Rightly? ( in other words,make relay-graph typechecked with graph no conflict)

@leebyron
Copy link
Contributor

I'm sorry, I'm having trouble understanding what you're asking.

It appears to me that Relay's resolver is potentially dangerously typed, since executor does not guarantee that source is an Object, nor that args always contains an input field.

I'm not sure what you mean by Template, could you elaborate what this is?

@iamchenxin
Copy link
Contributor Author

iamchenxin commented Jun 13, 2016

@leebyron Template is the T in function<T> () (a terminology from other language). I did not find official name for T in flowtype.org. That docs just called the using of Template is polymorphic. I am not sure, may be i missed something.
I checked source for this. top level source is emitted from one package, resolved in Graphql,and received by another package. So this makes its complex to give a polymorphic flow type for resolver.(Like in Graphql-relay . from something like express->graphql->graphql-relay)
So finally, i made a package (flow-dynamic ) to deal with those Flow Type conflict between packages , dynamic check data,and give them a corresponding Flow Type. Like this :

resolve: (obj, {id}, context, info) => idFetcher(id, context, info) //code from grapgql-relay

can typed with a flow-dynamic check

 resolve: argsCheck(
      args => ({id: pro.isString(args.id) }), //  this will give args a flow type {id:string}
      (obj, args, context, info) => idFetcher(args.id, context, info)
 )

The demonstration is here graphql-relay pr:89 (detail codes) .

Could you have a look at this solution? If it is suitable. Then Graphql can publish a flow typed output version for us.

@IvanGoncharov
Copy link
Member

Already implemented so you can specify types for both source and args:

export type GraphQLFieldResolver<
TSource,
TContext,
TArgs = { [argument: string]: any },
> = (

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

3 participants