graphql-to-reason icon indicating copy to clipboard operation
graphql-to-reason copied to clipboard

Trying to run clicks example from readme.

Open idkjs opened this issue 6 years ago • 4 comments

Version Package version

    "graphql-to-reason": "^1.0.0-alpha.0",

Describe the bug A clear and concise description of what the bug is. I added SchemaTypes.re

include SchemaTypes_builder.MakeSchema({
  module Scalars = {type click;};
  type resolver('parent, 'payload, 'fieldType, 'result) =
    ('parent) => Js.Promise.t('result);
  type directiveResolver('payload);
});

I added Clicks.re to which i had to curry the resolve function for it to compile.

let count = ref(0);
/* No need to explicitly type resolver, it will infer correct type later */
let resolver = (_node, _args, _context, _resolveInfo, _fieldInfo) =>
  Js.Promise.make((~resolve, ~reject) => {
    count := count^ + 1;
    resolve(. count^);
  });

I added Resolvers.re

let mutationResolvers =
  SchemaTypes.Mutation.t(~clicksCount=Clicks.resolver, ());

let resolvers = SchemaTypes.t(~mutation, ());

Which produces this error:

Error: The function applied to this argument has type
         (~click: GraphqlToReasonBasicExample.SchemaTypes.rootResolver(
                  {. "payload": int},
                   GraphqlToReasonBasicExample.SchemaTypes.click,
                   GraphqlToReasonBasicExample.SchemaTypes.click)=?) =>
         GraphqlToReasonBasicExample.SchemaTypes.Mutation.t
This argument cannot be applied with label ~clicksCount
Screenshot 2019-09-21 at 12 40 39 PM

How would these errors be resolved? Thanks.

Reproduction https://github.com/idkjs/graphql-to-reason-examples/tree/master/clicks-example

idkjs avatar Sep 21 '19 16:09 idkjs

Hey, error clearly states that your mutation is called clicks which comes from schema.graphql file

type Mutation {
    click(payload: String!): Click!
}

Do you want to fix readme?

Coobaha avatar Sep 23 '19 15:09 Coobaha

I had gone beyond that error but figured it was a think would recognize. When you do that, you get additional errors.

Example: changing ~clicksCount to ~clicks per error get you:

  We've found a bug for you!
  /Users/prisc_000/Downloads/clicks-example/src/Resolvers.re 14:33-47

  12 │  */
  13 │ let mutationResolvers =
  14 │   SchemaTypes.Mutation.t(~click=Clicks.resolver, ());
  15 │
  16 │ let resolvers = SchemaTypes.t(~mutation, ());

  This has type:
    (unit, 'a, 'b, 'c, 'd) => Js.Promise.t(int)
  But somewhere wanted:
    GraphqlToReasonBasicExample.SchemaTypes.rootResolver({. "payload":
                                                           string},
                                                          GraphqlToReasonBasicExample.SchemaTypes.click,
                                                          GraphqlToReasonBasicExample.SchemaTypes.click)
      (defined as
      unit => Js.Promise.t(GraphqlToReasonBasicExample.SchemaTypes.click))

  The incompatible parts:
    ('a, 'b, 'c, 'd) => Js.Promise.t(int)
    vs
    Js.Promise.t(GraphqlToReasonBasicExample.SchemaTypes.click) (defined as
      Js.Promise.t(GraphqlToReasonBasicExample.SchemaTypes.click))

>>>> Finish compiling(exit: 1)

I could not figure this one out.

idkjs avatar Sep 23 '19 15:09 idkjs

@idkjs

include SchemaTypes_builder.MakeSchema({
  module Scalars = {type click;};
  type resolver('parent, 'payload, 'fieldType, 'result) =
    ('parent) => Js.Promise.t('result);
  type directiveResolver('payload);
});

You created abstract type click, please check readme example again. It has int there :)

Coobaha avatar Sep 23 '19 15:09 Coobaha

When I add the int:

include SchemaTypes_builder.MakeSchema({
  module Scalars = {
    type click = int;
  };
  type resolver('parent, 'payload, 'fieldType, 'result) =
    'parent => Js.Promise.t('result);
  type directiveResolver('payload);
});

It throws this error:

  We've found a bug for you!
  /Users/prisc_000/Downloads/clicks-example/src/Resolvers.re 14:33-47

  12 │  */
  13 │ let mutationResolvers =
  14 │   SchemaTypes.Mutation.t(~click=Clicks.resolver, ());
  15 │
  16 │ let resolvers = SchemaTypes.t(~mutation, ());

  This call is missing arguments of type: 'a, 'b, 'c, 'd

>>>> Finish compiling(exit: 1)

I was just trying to figure it out by modeling the clicks after your basic example which works.

idkjs avatar Sep 23 '19 16:09 idkjs