GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
526 stars 66 forks source link

Potential Bug with Input types #115

Closed bhaze31 closed 1 year ago

bhaze31 commented 1 year ago

Vapor: 4.74.2 Graphiti: 1.10.0 GraphQL: 2.5.0 Pioneer 1.2.1

I am using a Codable struct as an input type for one of my mutations. I defined the Type in the schema itself as such:

Type(CreateLeagueArguments.self) {
        Field("name", at: \.name)
        Field("organizationId", at: \.organizationId)
        Field("level", at: \.level)
}

For the mutation I have:

Field("createOrganization", at: GameOnResolver.createOrganization) {
    Argument("title", at: \.title)
    Argument("info", at: \.info)
    Argument("leagueInfo", at: \.leagueInfo)
}

And the arguments struct for the resolver is:

struct CreateOrganizationArguments: Codable {
    var title: String
    var info: String
    var leagueInfo: CreateLeagueArguments?
}

However, when attempting to run the app, I get:

Fatal error: 'try!' expression unexpectedly raised an error: Cannot use type "Optional<CreateLeagueArguments>" for field "leagueInfo". Mapped GraphQL type is not an input type.

Happy to supply more context, and apologies if this isn't a bug.

NeedleInAJayStack commented 1 year ago

Hey @bhaze31, no worries about asking questions here.

In this case I think CreateLeagueArguments should be declared as an Input instead of a Type. Check out the Input Objects section of the Usage Guide for more info.

bhaze31 commented 1 year ago

@NeedleInAJayStack did not even know that Usage Guide existed, and that is exactly what I needed. Really appreciate the speedy response! Will close this out now