Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphQL Schema with multi-level operations fails to create GraphQLOperationRequest

See original GitHub issue

Issue Description

I have a schema like below

type Query {
    product: productQuery

type Mutation {
    product: productMutation

type productQuery  {
    productOrganization(id: ID!): productOrganization

type productOrganization {
    id: ID!

    enabled: Boolean!
    createdOn: DateTime!
    updatedOn: DateTime

Now when I use the codegen tool to generate models

the productQueryRequest implements GraphQLOperationRequest{} is generated without any params to link to productOrganization . as shown below

public class productQueryRequest implements GraphQLOperationRequest {
    public static final String OPERATION_NAME = "product";
    public static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.QUERY;

    private String alias;
    private final Map<String, Object> input = new LinkedHashMap<>();
    private final Set<String> useObjectMapperForInputSerialization = new HashSet<>();

    public productQueryRequest() {

    public productQueryRequest(String alias) {
        this.alias = alias;

The reason that I understand is the leveling I have in my query (3 levels) ; like query -> productQuery -> productOrganization has this been 2 levels it would have been fine like if query-> productOrganization.

Steps to Reproduce

List in detail the exact steps to reproduce the unexpected behavior.

Run the codegen on schema above

Expected Result

Explain in detail what behavior you expected to happen. I would expect productQuery in this case to have an injection for productOrganization in the model generated

Actual Result

Described above

Your Environment and Setup

  • graphql-java-codegen version: 5.4.0
  • Build tool: Maven
<!--                            <generateParameterizedFieldsResolvers>true</generateParameterizedFieldsResolvers>-->

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

atlas-tbrowncommented, Apr 27, 2022

+1 to this. We really really want to use this library but without this we can’t. We don’t want to follow the way that is listed because we need to follow nesting practices to keep our queries separate, eg: they may come from different sources.I’m not sure I’d consider it against best practices since isn’t the strong suite of graphql that queries can be nested? Either for this or for having fields that can take args and so on.

Any idea how much work this would be? Would possibly be able to help contribute.

Thanks for creating this library!

kobylynskyicommented, Mar 6, 2022

Overall your schema design looks not as per GraphQL best-practices. I think the better solution would be:

type Query {
    productOrganization(id: ID!): ProductOrganization

type ProductOrganization {
    id: ID!
    enabled: Boolean!
    createdOn: DateTime!
    updatedOn: DateTime
Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema basics - Apollo GraphQL Docs
This article describes the fundamental building blocks of a schema and how to create one for your GraphQL server. The schema definition language....
Read more >
Learn how GraphQL remote schemas work? - Prisma
With that knowledge, let's dive into how we can create an executable instance of GraphQLSchema based on an existing GraphQL API.
Read more >
What you need to know about GraphQL enums
Learn how GraphQL enums can help you build more robust and discoverable APIs, create simple interfaces, maintain slim resolvers, and more.
Read more >
Create a GraphQL schema - ServiceNow Docs
Create a GraphQL schema to make data available to GraphQL ... Perform record operations using ServiceNow CLI ... Action error evaluation.
Read more >
Introspection fails to load schema from server #7934 - GitHub
Create a codegen.yml that loads the schema from remote ... baseTypesPath: types/graphql.generated.ts plugins: - typescript-operations - typescript-urql `.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found