dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

bug: Non-default Root Operation Types are ignored

Open NfNitLoop opened this issue 3 years ago • 3 comments

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.

NfNitLoop avatar Oct 29 '21 00:10 NfNitLoop

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

paulbakker avatar Nov 10 '21 00:11 paulbakker

What's the use case?

In general, following the GraphQL spec? 😅

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

NfNitLoop avatar Nov 10 '21 00:11 NfNitLoop

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

mattlyons0 avatar Feb 03 '24 23:02 mattlyons0