Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.08k stars 296 forks source link

bug: Non-default Root Operation Types are ignored #713

Open NfNitLoop opened 3 years ago

NfNitLoop commented 3 years ago

Expected behavior

gradle generateJava should inspect the schema block for a schema to determine the Root Operation Types for the schema.

Actual behavior

The generator seems to just look for default operation types Query and Mutation. (I have not tested Subscription.) It completely ignores the schema block.

Steps to reproduce

With a build.gradle like this:

plugins {
    id "java"
    id "com.netflix.dgs.codegen" version "5.1.2"
}

repositories {
        jcenter()
        mavenCentral()
}

generateJava {
   schemaPaths = ["./schemas/"] 
   packageName = 'com.example.packagename'
   generateClient = true 
}

run gradle generateJava against a schema like this:

# This block is completely ignored:
schema {
  query: QueryRoot
  mutation: MutationRoot
}

type QueryRoot {
    strings(value: String): [String]
}

type MutationRoot {
  setStrings(value: [String]): [String]
}

I'd expect to get query classes for QueryRoot and MutationRoot but get neither.

However, if we modify the root type names to be the defaults, like this:

# This block is completely ignored:
# Note: This should probably additionally give us an error about missing QueryRoot and MutationRoot types!
schema {
  query: QueryRoot
  mutation: MutationRoot
}

type Query {
    strings(value: String): [String]
}

type Mutation {
  setStrings(value: [String]): [String]
}

The SetStringsGraphQLQuery and StringsGraphQLQuery classes do get generated.

paulbakker commented 2 years ago

Interesting, we don't typically use the schema definition like that. What's the use case?

NfNitLoop commented 2 years ago

What's the use case?

In general, following the GraphQL spec? 😅

In particular, Shopify's GraphQL API uses QueryRoot and MutationRoot as root objects.

mattlyons0 commented 9 months ago

Can confirm this is still an issue, I just ran into this in another GraphQL API.

It's definitely a part of the GraphQL spec as defined in https://spec.graphql.org/June2018/#sec-Schema