Skip to content

Argument default values and descriptions not available in introspection #880

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

Closed
mrtnzlml opened this issue Feb 18, 2021 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@mrtnzlml
Copy link

mrtnzlml commented Feb 18, 2021

Hello, me again! 😅

Describe the bug

Argument default values and descriptions are not available in introspection (and via as_schema_language). I followed this syntax: https://graphql-rust.github.io/juniper/master/types/objects/complex_fields.html?highlight=arguments#customizing-arguments

To Reproduce

  1. create a field with arguments like so:
#[juniper::graphql_object]
impl Product {
    #[juniper::graphql(arguments(first(default = 1, description = "TEST")))]
    fn images(&self, first: i32) -> Vec<Image> {
        // …
    }
    // …
}
  1. introspect the schema and try to get the default value and description (it's not there)

Expected behavior

The default value and description should be available via introspection.

Additional context

Here is how the introspection looks like in my case (notice the missing arg description and default value):

{
  name: "images",
  description: "A list of images for this product, meant to be displayable to the customer.",
  args: [
    {
      name: "first",
      description: null,
      type: {
        kind: "NON_NULL",
        name: null,
        ofType: {
          kind: "SCALAR",
          name: "Int",
          ofType: null,
        },
      },
      defaultValue: null,
    },
  ],
  type: {
    kind: "NON_NULL",
    name: null,
    ofType: {
      kind: "LIST",
      name: null,
      ofType: {
        kind: "NON_NULL",
        name: null,
        ofType: {
          kind: "OBJECT",
          name: "Image",
          ofType: null,
        },
      },
    },
  },
  isDeprecated: false,
  deprecationReason: null,
}
@mrtnzlml mrtnzlml added bug Something isn't working needs-triage labels Feb 18, 2021
@tyranron
Copy link
Member

@mrtnzlml the attribute on a field should be without a prefix: #[graphql(...)], not #[juniper::graphql(...)].

@mrtnzlml
Copy link
Author

@tyranron I just tried to write it like this and it doesn't seem to make any difference:

#[juniper::graphql_object]
impl Product {
    #[graphql(arguments(first(default = 1, description = "TEST")))]
    fn images(&self, first: i32) -> Vec<Image> {
        // …
    }
    // …
}

This also makes me think: should it throw some error when I use juniper::graphql? Newbie question.

@tyranron
Copy link
Member

@mrtnzlml it should work, there is a lot of open code proving it works, including integrations tests in this repository. Maybe you miss some step.

should it throw some error when I use juniper::graphql?

Hmm... not sure. What about graphl or grapql? Should it throw error too? For proc_matro_attribute we only search for the attributes we're interested in, and don't touch other ones. I'm unsure the "maybe this attribute is something we need, but is mispelled" is a good way to go.

@LegNeato
Copy link
Member

Could you put up a PR with a failing test? As @tyranron mentioned we appear to have tests covering this so there must be something we are missing.

@mrtnzlml
Copy link
Author

mrtnzlml commented Mar 1, 2021

Yes, would like to do it. However, I still didn't isolate why is it happening. Please, leave this issue open for a bit longer. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants