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

Introspection error when defining an argument with default value. #70

Closed
rantingmong opened this issue Oct 14, 2021 · 3 comments
Closed

Comments

@rantingmong
Copy link

rantingmong commented Oct 14, 2021

Given this schema config:

let schema = try Graphiti.Schema<ResolverRoot, Request> {
    Scalar(UUID.self)

    // define graphql types
    
    Query {
        Field("profile", at: ResolverRoot.profile, as: [Profile].self) {
            Argument("input", at: \.input).defaultValue(.init(page: 0, limit: 10))
        }
    }
    Mutation {
        Field("createProfile", at: ResolverRoot.createProfile, as: Profile.self) {
            Argument("input", at: \.input)
        }
    }
}

When asked to be introspected it returns an error:

  • On Jetbrains Webstorm:

A valid schema could not be built using the introspection result. The endpoint may not follow the GraphQL Specification.
Error: internal error: should never happen: valueFromAst of '{"limit":10,"page":0}' failed because of 'Invalid Syntax : offending token '"limit"' at line 1 column 25'

  • On Insomnia

Failed to fetch schema: Syntax Error: Expected Name, found string "limit"

Removing the .defaultValue(...) fixes the problem but runs the impossibility of not having a default value on an optional argument in the query.

More context

The input defined is a generic struct:

struct Input<Payload: Codable>: Codable {
    let input: Payload
}

And the payload:

struct ProfileQueryInput: Codable {
    let page: Int
    var limit: Int = 10
}

When defining the GQL types, only ProfileQueryInput and not Input<ProfileQueryInput> is defined in the schema config.

@d-exclaimation
Copy link
Member

I couldn't reproduce the issue. From your explanation, nothing seemed out of the ordinary.

I am guess this

struct Input<Payload: Codable>: Codable {
    let input: Payload
}

is for the arguments.

I tried with a generic Input (Argument structs) and with one without using generic Input. In both cases, all introspection queries are resolved properly. Apollo Sandbox, GraphiQL, and GraphQL Playground have no issue with the introspection result as well. Haven't checked Insomnia and Jetbrains Webstorm, but they shouldn't have issue with the result if GraphiQL doesn't.

The example I used is here

@NeedleInAJayStack
Copy link
Member

Thanks for looking at this @d-exclaimation! Hopefully it was taken care of by some fixes over the past year.

@rantingmong - Are you still experiencing this issue on the most recent Graphiti version?

@NeedleInAJayStack
Copy link
Member

I'm closing this with the can't reproduce status. Thanks everyone!

@NeedleInAJayStack NeedleInAJayStack closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2023
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

3 participants