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

Configure validation of the graphql schema #566

Open
4 tasks done
SorsOps opened this issue Apr 3, 2023 · 1 comment
Open
4 tasks done

Configure validation of the graphql schema #566

SorsOps opened this issue Apr 3, 2023 · 1 comment
Labels
feature-request New feature or request p4

Comments

@SorsOps
Copy link

SorsOps commented Apr 3, 2023

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v18.15.0

Amplify CLI Version

11.0.3

What operating system are you using?

Windows

Amplify Codegen Command

codegen

Describe the bug

During code generation for typescript types, a union causes type generation to fail due to conflicting types on the schema

Expected behavior

It generates the correct graphqlTypes.ts without issue for conflicting types. If necessary provide configuration to turn off graphql validation for this rule

Reproduction steps

  1. Setup codegen with defaults
  2. Use the supplied graphql schema
  3. Run amplify codegen

GraphQL schema(s)

# Put schemas below this line
schema {
  query: Query
}

type Query{
  get: [Unioned]
}

union Unioned = Simple | More_Complex


type Complex {
  foo: String
}

type More_Complex  {
  value: Complex
}

type Simple {
  value: String
}


Log output

# Put your logs below this line

- Generating.../XX/graphql/queries.ts: Fields "value" conflict because they return conflicting types "String" and "Complex". Use different aliases on the fields to fetch both if this was intentional.
.../XX/graphql/queries.ts: Fields "value" conflict because they return conflicting types "String" and "Complex". Use different aliases on the fields to fetch both if this was intentional.
✖ Validation of GraphQL query document failed

Additional information

Here is the output with graphql validation turned off. This is what I want

/* tslint:disable */
/* eslint-disable */
//  This file was automatically generated and should not be edited.

export type Unioned = Simple | More_Complex


export type Simple = {
  __typename: "Simple",
  value?: string | null,
};

export type More_Complex = {
  __typename: "More_Complex",
  value?: Complex | null,
};

export type Complex = {
  __typename: "Complex",
  foo?: string | null,
};

export type GetQuery = {
  get:  Array<( {
      __typename: "Simple",
      value?: string | null,
    } | {
      __typename: "More_Complex",
      value?:  {
        __typename: string,
        foo?: string | null,
      } | null,
    }
  ) | null > | null,
};

@alharris-at alharris-at added feature-request New feature or request p4 labels Apr 27, 2023
@alharris-at
Copy link
Contributor

Hi @SorsOps, thank you for reaching out. Today I believe this restriction exists because the underlying transformer which this codegen was based on does not support union types or interfaces, but it's possible we can restrict the validation here (especially if you're not using the Amplify CLI to define or push your GraphQL API). I've marked this as a feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request p4
Projects
None yet
Development

No branches or pull requests

2 participants