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.

ValuesOfCorrectType is not correctly implementing the spec

See original GitHub issue

As 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
IvanGoncharovcommented, Oct 21, 2019

@attilah Can I close this issue or you still have some questions?

0reactions
attilahcommented, Oct 21, 2019

Sure, yes, I will ping you if I encounter any further issue when I get back to this.

Read more comments on GitHub >

github_iconTop 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 >

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