Comments (6)
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.
@yoadsn looking at it
from graffiti-mongoose.
feel free to open the PR, I will try to fix the tests
from graffiti-mongoose.
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.
@yoadsn Thank you, I really appreciate!
from graffiti-mongoose.
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)
- Implicit dependency on babel-polyfill HOT 9
- Cannot set currently-valued fields to null in update mutation HOT 2
- How to make a custom field: id? HOT 10
- Custom query thunk - accepts only InputObject types HOT 3
- Question on customQueries HOT 7
- Example project doesnt work with [email protected] and [email protected] HOT 1
- Async hook support HOT 2
- How to use Express Middleware for Authentication/Authorization. HOT 4
- Get specific field validation error?
- How to mutate nested Schema? HOT 3
- What is different between id and _id HOT 1
- UNMET PEER DEPENDENCY HOT 1
- Maintainer Volunteer Thread HOT 1
- Mongoose ObjectId and GraphQL id is not the same. How to link them? HOT 5
- It is possible to add some description to schema and to be reflected in the docs?
- Does graffiti-mongoose works with react-apollo ? HOT 2
- Custom mutations?
- Custom queries/mutations HOT 1
- setTypeFields bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graffiti-mongoose.