Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter enforcement on optional or default values #34

Open
xsist10 opened this issue Jan 22, 2019 · 1 comment
Open

Parameter enforcement on optional or default values #34

xsist10 opened this issue Jan 22, 2019 · 1 comment

Comments

@xsist10
Copy link

xsist10 commented Jan 22, 2019

I think the validation rules are not taking default and nullable parameter configurations into account when validating the query.

I have a schema definition that includes a query that takes two parameters both marked as nullable (no ! post-fix) and both with the default value set to null.

The schema looks like this:

type Records {
    id : Int!
   external_id : Int
}

type Query {
    get_records(id : Int = null, external_id : Int = null) : [Records]
}

schema {
    query : Query
}

When I run the following query:

query TestQuery {
    get_records {
        id
    }
}

I get this error Message:

The `schema.field(get_records)` and `query.field(get_records)` both must expect arguments, not `yes` and `no`"

And when I run the following query:

query TestQuery {
    get_records(id: 1) {
        id
    }
}

I get this error Message:

The `schema.field(get_records).arity` and `query.field(get_records).arity` must match, not `2` and `1`
@xsist10
Copy link
Author

xsist10 commented Jan 22, 2019

Added test

use strict;
use warnings;

use Graph::QL::Schema;
use Graph::QL::Operation;
use Graph::QL::Execution::QueryValidator;

use Test::More;

my $schema = Graph::QL::Schema->new_from_source(q[
    type Records {
        id : Int!
        external_id : Int
    }

    type Query {
        get_records(id : Int = null, external_id : Int = null) : [Records]
    }

    schema {
        query : Query
    }
]);

my @queries = (
    q[
        query TestQuery {
            get_records {
                id
            }
        }
    ],
    q[
        query TestQuery {
            get_records(id: 1) {
                id
            }
        }
    ],
);

foreach (@queries) {
    my $operation = Graph::QL::Operation->new_from_source($_);

    # Perform validation first
    my $validator = Graph::QL::Execution::QueryValidator->new(
        schema    => $schema,
        operation => $operation,
    );

    # Check if all the validation steps passed
    my $validate = $validator->validate();
    my $messages = join("\n", $validator->get_errors());
    ok($validate, "Query $_ passes the parameter validation checks properly with messages: $messages.");

}

done_testing();

1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant