Coder Social home page Coder Social logo

Comments (6)

yoadsn avatar yoadsn commented on June 23, 2024

I suspect this might be a bug in Graphql.js itself. since in the "type" docs of Graphql the "args" property of a field is optional. From here:

type GraphQLFieldConfig = {
  type: GraphQLOutputType;
  args?: GraphQLFieldConfigArgumentMap;
  resolve?: GraphQLFieldResolveFn;
  deprecationReason?: string;
  description?: ?string;
}

Should I open a bug in graphql?

from graffiti-mongoose.

tothandras avatar tothandras commented on June 23, 2024

@yoadsn looking at it

from graffiti-mongoose.

tothandras avatar tothandras commented on June 23, 2024

feel free to open the PR, I will try to fix the tests

from graffiti-mongoose.

yoadsn avatar yoadsn commented on June 23, 2024

After many hours of debugging- I think I have found the problem - deep inside the type.js source code.
I will update later when I have a suggestion for a fix.

from graffiti-mongoose.

tothandras avatar tothandras commented on June 23, 2024

@yoadsn Thank you, I really appreciate!

from graffiti-mongoose.

yoadsn avatar yoadsn commented on June 23, 2024

Ok, For future reference here is a brief of the problem and how it was resolved.

Since ever, graphql was memoizing access to the getFields() method of a GraphQLObjectType so that the calculation is stored internally on the _fields property and returned from that field if already calculated.

 getFields(): GraphQLFieldDefinitionMap {
    return this._fields || (this._fields =
      defineFieldMap(this, this._typeConfig.fields)
    );
  }

code here;

Now, graffiti-mongoose generates fields with reference and attaches the correct types to those fields in a big method getTypes() in type.js.
During that process in order to get the fields of a parent field of a reference field it uses the graphql getFields() method unlike how it does it for other types of fields (such as an array of reference fields).

parent = parent[segment].type.getFields();

code here

The parent variable is the internal _fields property of the GraphQLObjectType and a few rows below it is modified (partially overridden) by the correct reference type field prepared beforehand. That pre-made field does not have an empty args property and it overrides the correct value in _fields generated by graphql which did contain the args property.

Later on, when the schema and inside it that specific GraphQLObjectType object is used by graphql it checks for the existence of the args field. (which is a mistake since the spec does not require it - see above).
But since graphql assumed internal properties like _fields are under the library control - it is a reasonable invariant to assert.

The fix was to enumerate the fields using an external method which does not call the internal memoizing leaving the object "clean".

parent = getTypeFields(parent[segment].type);

This is how other fields were populated in other parts of that method.
This bug was most likely caused by this commit

from graffiti-mongoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.