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

Custom types can't be referenced more than once #14104

Open
3 tasks done
Erid opened this issue Dec 31, 2024 · 2 comments
Open
3 tasks done

Custom types can't be referenced more than once #14104

Erid opened this issue Dec 31, 2024 · 2 comments
Assignees
Labels
GraphQL Related to GraphQL API issues not-reproducible Not able to reproduce the issue pending-maintainer-response Issue is pending a response from the Amplify team.

Comments

@Erid
Copy link

Erid commented Dec 31, 2024

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify Gen 2

Environment information

# Put output below this line
  System:
    OS: macOS 15.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 53.89 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 8.15.9 - ~/.asdf/installs/nodejs/20.10.0/bin/pnpm
    bun: 1.0.25 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 131.0.6778.205
    Edge: 131.0.2903.112
    Safari: 18.2
  npmPackages:
    @aws-amplify/auth: 6.9.0 => 6.9.0 
    @aws-amplify/backend: 1.11.0 => 1.11.0 
    @aws-amplify/backend-cli: 1.4.5 => 1.4.5 
    @aws-sdk/client-cognito-identity-provider: 3.716.0 => 3.716.0 
    @aws-sdk/client-lambda: 3.716.0 => 3.716.0 
    @aws-sdk/client-s3: 3.717.0 => 3.717.0 
    @aws-sdk/s3-request-presigner: 3.717.0 => 3.717.0 
    @empat/core: workspace:* => 1.0.0 
    @empat/eslint-config: workspace:* => 1.0.0 
    @types/aws-lambda: 8.10.146 => 8.10.146 
    aws-amplify: 6.11.0 => 6.11.0 
    aws-cdk: 2.173.2 => 2.173.2 
    aws-cdk-lib: 2.173.2 => 2.173.2 
    constructs: 10.4.2 => 10.4.2 
    dotenv: 16.4.5 => 16.4.5 
    esbuild: 0.24.0 => 0.24.0 
    graphql-request: 7.1.0 => 7.1.0 
    openai: 4.68.4 => 4.68.4 
    tsx: 4.19.1 => 4.19.1 
    typescript: 5.7.2 => 5.7.2 
    vitest: 2.1.3 => 2.1.3 
  npmGlobalPackages:
    @builder.io/micro-agent: 0.1.5
    @githubnext/github-copilot-cli: 0.1.36
    corepack: 0.22.0
    hasura-cli: 2.35.2
    npm: 10.2.3

Describe the bug

When defining a custom type, if I try to reference it as the return type of a query, it works, however, if I do it on more than one query it throws an error.

Expected behavior

I would expect the Schema to let me reference the same custom type more than once.

Reproduction steps

  1. Define a custom type, like:
CustomType: a.customType({
  id: a.string().required(),
  name: a.string().required(),
}),
  1. Then reference it to be part of the result of a query, like this:
getSomething: a
  .query()
  .arguments({
    arg1: a.string().required(),
  })
  .returns(a.ref("CustomType").required().array().required())
  .handler(a.handler.function(getSomething))
  .authorization((allow) => [allow.group("Admin")]),
  1. That works just as expected, however, then create another query that returns the same type, and get the following error:
api dev: Failed to instantiate data construct
api dev: Caused By: Schema validation failed.\n\nThe directive "@aws_cognito_user_pools" can only be used once at this location.\n\nGraphQL request:259:16\n258 |\n259 | type CustomType @aws_cognito_user_pools @aws_api_key @aws_cognito_user_pools(cognito_groups: ["Admin"])\n    |                ^\n260 | {\n\nGraphQL request:259:53\n258 |\n259 | type CustomType @aws_cognito_user_pools @aws_api_key @aws_cognito_user_pools(cognito_groups: ["Admin"])\n    |                                                     ^\n260 | {
api dev: Resolution: See the underlying error message for more details.
api dev: [Sandbox] Watching for file changes...
@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Dec 31, 2024
@Erid Erid changed the title Custom types can't be referenced more than oncex Custom types can't be referenced more than once Dec 31, 2024
@cwomack cwomack added the GraphQL Related to GraphQL API issues label Dec 31, 2024
@chrisbonifacio chrisbonifacio self-assigned this Jan 2, 2025
@chrisbonifacio chrisbonifacio added the to-be-reproduced Used in order for Amplify to reproduce said issue label Jan 2, 2025
@chrisbonifacio
Copy link
Member

Hi @Erid , thanks for raising this issue and providing reproduction steps. Unfortunately, I have not been able to reproduce the behavior described in this issue.

I tried deploying this schema:

  CustomType: a.customType({
    id: a.string().required(),
    name: a.string().required(),
  }),
  getSomething: a
    .query()
    .arguments({
      arg1: a.string().required(),
    })
    .returns(a.ref("CustomType").required().array().required())
    .handler(a.handler.function(getSomething))
    .authorization((allow) => [allow.group("Admin")]),
  getSomething2: a
    .query()
    .arguments({
      arg1: a.string().required(),
    })
    .returns(a.ref("CustomType").required().array().required())
    .handler(a.handler.function(getSomething))
    .authorization((allow) => [allow.group("Admin")]),

but was able to compile and deploy successfully.

Can you confirm you are using the latest versions of the @aws-amplify/backend packages?

@chrisbonifacio chrisbonifacio added pending-community-response Issue is pending a response from the author or community. not-reproducible Not able to reproduce the issue and removed pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. to-be-reproduced Used in order for Amplify to reproduce said issue labels Jan 3, 2025
@Erid
Copy link
Author

Erid commented Jan 3, 2025

Thanks for the reply @chrisbonifacio, it's odd, I was positive that was enough to reproduce, but maybe I missed something. I'll try to reproduce by creating a new project and introduce parts of the schema bit by bit; since I can't share the company's code.

And yes, I have version 1.11.0. I'll share my project as soon as I can take to some time to reproduce, hopefully Today, if not, next week.

@github-actions github-actions bot added pending-maintainer-response Issue is pending a response from the Amplify team. and removed pending-community-response Issue is pending a response from the author or community. labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GraphQL Related to GraphQL API issues not-reproducible Not able to reproduce the issue pending-maintainer-response Issue is pending a response from the Amplify team.
Projects
None yet
Development

No branches or pull requests

3 participants