question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference Equality Check in VariableTypesMatchRule breaks if GraphQLInputObjectType is created multiple times.

See original GitHub issue

Normally in schema creation, it is OK to create multiple instances of the same type object. However, VariableTypesMatchRule uses reference equality, so if I create my schema with multiple instances of an equivalent GraphQLObjectInputType then I will get validation failures. This was tricky to track down because I create input types in methods (e.g. private GraphQLInputObjectType createPropertyMatchType()) and then call those methods when I need it them.

I think the ideal solution is to use deep equality instead of reference equality in VariableTypeMatchRule.

Otherwise some process in schema creation should canonicalize the types within the schema.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:26 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
dminkovskycommented, Oct 20, 2016

From this, I infer that two types with the same name must be equal or the schema is invalid.

Right: they must be equal according to the spec. But what if due to say, a bug, they are not?

Say I have one spot in my code where I have:

newObject
  .name("Obj")
  .field(newFieldDefinition()
    .name("field")
    .type(GraphQLString)
    .build())
  .build()

and another where:

newObject
  .name("Obj")
  .field(newFieldDefinition()
    .name("field")
    .type(GraphQLInt)
    .build())
  .build()

then, say, in some other code I compare these definitions and the result is they are equivalent. Then how much longer down the line will this bug manifest?

My point is—and sorry truly if I am missing something or am just being too pedantic—that yes, the spec says a type’s name should be unique. But from a runtime Java perspective, two object definitions with the same name can be totally different, and the usefulness of an equivalence relation that only compares their names seems, well, not useful, and even worse, bug prone?

1reaction
yrashkcommented, May 6, 2016

Nothing is stopping them to do so. What we can do is to refuse adding two unequal types with the same name to the schema, proactively, so this type of mistake can be caught early.

On Friday, 6 May 2016, danielkwinsor notifications@github.com wrote:

In terms of my graphql-java-type-generator, it stores types with key == type name, so there cannot be duplicate GraphQL types. Further, the default type name is the FQN with underscores, also with the ability to override the name. (But actually I did realize something I could do better).

So actually I am thinking in the more general case. What is to stop a user from hand coding 2 AccountTypes, which then may or may not be equal if we make an equality change?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/graphql-java/graphql-java/issues/85#issuecomment-217508577

Y.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test for reference equality (Identity) - C# guide
The following example shows how to determine whether two variables have reference equality, which means that they refer to the same object ...
Read more >
Scala match and reference equality check - Stack Overflow
1 Answer 1 ... There is a contract for equals . x.equals(x) has to be true. If you break that contract, a lot...
Read more >
Index (graphql-java 230521-nf-execution API) - Javadoc.io
A factory method for creating asynchronous data fetchers so that when used with ... Can be called multiple times to change the current...
Read more >
Reading 15: Equality - MIT
Understand equality defined in terms of the abstraction function, an equivalence relation, and observations. Differentiate between reference equality and object ...
Read more >
Equality (==) - JavaScript - MDN Web Docs
The equality (==) operator checks whether its two operands are equal, returning a Boolean result. Unlike the strict equality operator, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found