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

CanDirective args Argument value is of type 'ArrayValue', expected a scalar #2263

Open
Stevemoretz opened this issue Dec 28, 2022 · 2 comments
Labels
discussion Requires input from multiple people

Comments

@Stevemoretz
Copy link
Contributor

I use the GraphQL plugin for intellij suggested by the official docs, but it gives me an error when adding an array to args of @can

Screen Shot 1401-10-07 at 19 10 32

The message is:

'createProperty' uses an illegal value for the argument 'args' on directive 'can'. Argument value is of type 'ArrayValue', expected a scalar

Describe the bug

type Mutation {
    createProperty(input: PropertyCreationInput @spread): Property @can(ability: "wp:role", args: [1,2], model: "App\\Models\\User")
}

So the args with [1,2] is the problem.

This is the defined type at schema-directives.graphql which comes from /vendor/nuwave/lighthouse/src/Auth/CanDirective.php

"""
Any constant literal value: https://graphql.github.io/graphql-spec/draft/#sec-Input-Values
"""
scalar CanArgs

Shouldn't that be something like instead?

scalar CanArgs @scalar(class: "a class here")

Expected behavior/Solution

Steps to reproduce

  1. You can just use the example from the docs and add the args to it:
type Mutation {
  createBlogPost(input: PostInput!): BlogPost
    @can(ability: "create", model: "App\\Post", args: [1,2])
}
  1. You can now see createBlogPost is underlined and red in intellij with this error: 'createBlogPost' uses an illegal value for the argument 'args' on directive 'can'. Argument value is of type 'ArrayValue', expected a scalar

Output/Logs

Click to expand
# Add in log output/error messages here

Lighthouse Version : v5.67.0

@spawnia spawnia added the discussion Requires input from multiple people label Dec 28, 2022
@spawnia
Copy link
Collaborator

spawnia commented Dec 28, 2022

I believe there is nothing we can do to fix this. The GraphQL specification distinguishes between scalars and lists, see https://spec.graphql.org/draft/#sel-FAFdFABAB6EugR

Field and directive arguments accept input values of various literal primitives; input values can be scalars, enumeration values, lists, or input objects.

Since input types can not be polymorphic, I believe it is impossible to express that the type of args can be any input value.

In your specific case, the plugin would probably be fine when defining the directive as args: [CanArgs] - but that would then break use cases where any other value such as args: "foo" is passed.

@Stevemoretz
Copy link
Contributor Author

Stevemoretz commented Dec 28, 2022

I believe there is nothing we can do to fix this. The GraphQL specification distinguishes between scalars and lists, see https://spec.graphql.org/draft/#sel-FAFdFABAB6EugR

Field and directive arguments accept input values of various literal primitives; input values can be scalars, enumeration values, lists, or input objects.

Since input types can not be polymorphic, I believe it is impossible to express that the type of args can be any input value.

In your specific case, the plugin would probably be fine when defining the directive as args: [CanArgs] - but that would then break use cases where any other value such as args: "foo" is passed.

Thanks for responding can't we use Unions though?

Update: input values can't be unioned I guess that's impossible then....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Requires input from multiple people
Projects
None yet
Development

No branches or pull requests

2 participants