Skip to content

generate graphql-client-code fails with SyntaxError: Unexpected <EOF> when schema uses @function resolvers #3280

Description

@fomson

Environment information

- Amplify CLI: `@aws-amplify/backend-cli` (tested 1.8.0 and latest)
- Node: v22.12.0 (also reproducible on v20.19.4 in CI)
- OS: macOS (also fails in Amplify Console build environment)
- Framework: Next.js 15, Amplify Gen 2

Describe the bug

ampx generate graphql-client-code --format graphql-codegen fails with a SyntaxError: Unexpected <EOF> when the schema contains mutations or queries backed by @function resolvers.

Reproduction steps

  1. Create an Amplify Gen 2 project with a schema that includes @function resolvers:
type Mutation {
  myCustomMutation(input: MyInput!): MyResult
    @function(name: "myLambdaFunction")
    @aws_cognito_user_pools
}
  1. Deploy the backend (so outputs exist)

  2. Run:

npx ampx generate graphql-client-code --format graphql-codegen --branch dev --app-id <your-app-id>

Expected behavior

Codegen generates TypeScript types and operation documents for all schema types, skipping @function-backed operations gracefully (or generating stub operations for them).

Actual behavior

[SyntaxError] Syntax Error: Unexpected <EOF> (4:1)
  2 | 
  3 | 
> 4 | 
    | ^

The codegen appears to generate an empty .graphql operations file (because @function resolvers don't produce auto-generated client operations), and then the GraphQL parser attempts to parse the empty file and crashes on EOF.

Workaround

Using @graphql-codegen/cli (community package) with the typescript plugin reading schema.graphql directly generates schema types successfully. Frontend per-operation types (MutationVariables, QueryResult) are maintained manually.

Impact

Any Gen 2 project using @function resolvers cannot use the native ampx generate graphql-client-code command. This forces manual maintenance of frontend type files, which is error-prone and increases development overhead.

Additional context

  • This has persisted across multiple CLI versions over the past year
  • The project has 50+ mutations/queries, most backed by @function resolvers
  • The @graphql-codegen/cli workaround works for Lambda types but cannot generate the per-operation types that ampx would normally produce

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-triageIncoming issues that need categorization

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions