ValuesOfCorrectType is not correctly implementing the spec
See original GitHub issueAs the spec states, this rule should validate that a given document is conforming to the schema, by verifying the type of fields for any given type.
When the schema defines a List type with non-null items and an Object is passed in the document, validation is not failing.
Schema:
type Post {
id: ID!
title: String
content: String
}
input UpdatePostInput {
id: ID!
title: String
content: String
}
input PostConditionInput {
title: StringConditionInput
content: StringConditionInput
and: [PostConditionInput!]
}
input StringConditionInput {
contains: String
}
type Mutation {
updatePost(input: UpdatePostInput!, conditions: PostConditionInput): Post
}
type Query {
listPosts : [Post!]!
}
Document:
mutation InvalidUpdate {
updatePost(
input: {
id: "P1"
title: "New Title"
content: "New Content"
}
conditions: {
and: {
title: { contains: "ABC" }
content: { contains: "DEF" }
}
}
) {
id
title
content
}
}
mutation ValidUpdate {
updatePost(
input: {
id: "P1"
title: "New Title"
content: "New Content"
}
conditions: {
and: [
{ title: { contains: "ABC" } }
{ content: { contains: "DEF" } }
]
}
) {
id
title
content
}
}
Notice that and is an object instead of an array in InvalidUpdate mutation, which would be valid, if a single object would be coerced into a single element array after parse and the object would be validated against the type of the list item.
The document above is passing validation, with the following code, using the latest 14.x version of the library.
import * as fs from 'fs';
import { buildSchema, parse } from 'graphql';
import { GraphQLSchema } from 'graphql/type';
import { validate, specifiedRules } from 'graphql/validation';
const schema = fs.readFileSync('schema.graphql').toString();
const mutation = fs.readFileSync('mutation.graphql').toString();
const rules = specifiedRules;
const schemaObject: GraphQLSchema = buildSchema(schema);
const document = parse(mutation);
const validataionResult = validate(schemaObject, document, rules);
console.log(JSON.stringify(validataionResult, null, 2));
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
c++ - How can I safely ensure a char* type will be correctly ...
In practice GLchar will look to a C++ compiler just like char and everything is fine (in languages where typedefs are not aliases...
Read more >Common Problems Found in RAML 1.0 API Specifications
Therefore, either the type is declared incorrectly in this example and should be integer , or the enum values need to be in...
Read more >Query - Amazon DynamoDB - AWS Documentation
DynamoDB calculates the number of read capacity units consumed based on item size, not on the amount of data that is returned to...
Read more >3.7 Function Specifications
We say that a function implementation is correct when the following holds: For all inputs that satisfy the specification's preconditions, the function ...
Read more >unittest.mock — mock object library — Python 3.11.1 ...
For mocks replacing a class, their return value (the 'instance') will have the same spec as the class. See the create_autospec() function and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@attilah Can I close this issue or you still have some questions?
Sure, yes, I will ping you if I encounter any further issue when I get back to this.