jlouis / graphql-erlang

GraphQL implementation in Erlang.
Other
313 stars 52 forks source link

bug in graphql:type_check_params/3? #205

Open leoliu opened 5 years ago

leoliu commented 5 years ago

Using v0.15.0 here.

type Mutation {
  createTicket(ticket: TicketInput!): Ticket
}

input TicketInput {
  name: String!
  email: Email!
  comment: String!
  reason: String!
  phone: Phone
}

type Ticket implements Node {
  id: ID!

  name: String!
  email: Email!
  comment: String!
  reason: String!
  phone: Phone
}

I can provide a boolean value to name and graphql:type_check_params/3 happily succeeds in this case.

(<0.1060.0>) call graphql:type_check_params(#{<<"CreateTicket">> =>
      #{<<"ticket">> =>
            {vardef,
                {name,1,<<"ticket">>},
                {non_null,
                    {input_object_type,<<"TicketInput">>,
                        <<"No description provided">>,[],
                        #{<<"comment">> =>
                              {schema_arg,
                                  {non_null,<<"String">>},
                                  null,<<"No description provided">>,[]},
                          <<"email">> =>
                              {schema_arg,
                                  {non_null,<<"Email">>},
                                  null,<<"No description provided">>,[]},
                          <<"name">> =>
                              {schema_arg,
                                  {non_null,<<"String">>},
                                  null,<<"No description provided">>,[]},
                          <<"phone">> =>
                              {schema_arg,<<"Phone">>,null,
                                  <<"No description provided">>,[]},
                          <<"reason">> =>
                              {schema_arg,
                                  {non_null,<<"String">>},
                                  null,<<"No description provided">>,[]}}}},
                null}}},undefined,#{<<"ticket">> =>
      #{<<"comment">> => <<"test">>,<<"email">> => <<"me@example.com">>,
        <<"name">> => true,<<"phone">> => <<"1234">>,
        <<"reason">> => <<"test">>}}) ({ceres_graphql_h,execute,2})
(<0.1060.0>) returned from graphql:type_check_params/3 -> #{<<"ticket">> =>
                                                                #{<<"comment">> =>
                                                                      <<"test">>,
                                                                  <<"email">> =>
                                                                      <<"me@example.com">>,
                                                                  <<"name">> =>
                                                                      true,
                                                                  <<"phone">> =>
                                                                      <<"1234">>,
                                                                  <<"reason">> =>
                                                                      <<"test">>}}
(<0.1060.0>) returning to ceres_graphql_h:execute/2

New to graphql and this application in particular, am I doing something wrong or is this a bug?

jlouis commented 5 years ago

Hi!

It is currently a bug because we still have to do some input coercion on binary types:

https://github.com/shopgun/graphql-erlang/blob/develop/src/graphql_scalar_binary_coerce.erl#L5

The specification is somewhat lax in this case. We should probably convert the atoms true and false into <<"true">> and <<"false">>`, IIRC what the spec is saying.

leoliu commented 5 years ago

Thanks for the update.