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

Invalid GraphQL schema: There can be only one directive named "@aws_cognito_user_pools". #590

Open
kuda1992 opened this issue Apr 4, 2023 · 3 comments

Comments

@kuda1992
Copy link

kuda1992 commented Apr 4, 2023

Hey there

I am using app-sync directives inside my graphql schema

directive @aws_cognito_user_pools on FIELD | OBJECT | INPUT_FIELD_DEFINITION | INPUT_OBJECT | MUTATION | ENUM | OBJECT | INTERFACE | UNION | SCALAR

schema {
    query: Query
    mutation: Mutation
}

type Account @aws_cognito_user_pools {
    AccountHoldersName: String
    AccountNo: String
    BuildingSocReference: String
    SortCode: String
}

However when I upload this using the serverless framework I am getting error

Error: Invalid GraphQL schema:
     There can be only one directive named "@aws_cognito_user_pools".

This used to work with the previous v1. Do you have an idea what the problem might be

@fetree
Copy link

fetree commented May 12, 2023

Running into this problem as well with globbing

There can be only one directive named "@aws_iam".
There can be only one directive named "@aws_api_key".
There can be only one directive named "@aws_oidc".

@kuda1992
Copy link
Author

kuda1992 commented Jun 7, 2023

Hi @bboure

In relation to the issue above I was wondering if you have managed to look it. I debugged the code and have found the offending code.

src/resources/Schema.ts

inside the

generateSchema() {
    const schemaFiles = flatten(globby.sync(this.schemas));
    const schemas = schemaFiles.map((file) => {
      return fs.readFileSync(
        path.join(this.api.plugin.serverless.config.servicePath, file),
        'utf8',
      );
    });

    this.valdiateSchema(AWS_TYPES + '\n' + schemas.join('\n'));

    // Return single files as-is.
    if (schemas.length === 1) {
      return schemas[0];
    }

    // AppSync does not support Object extensions
    // https://spec.graphql.org/October2021/#sec-Object-Extensions
    // Merge the schemas
    return print(
      mergeTypeDefs(schemas, {
        forceSchemaDefinition: false,
        useSchemaDefinition: false,
        sort: true,
        throwOnConflict: true,
      }),
    );
  }

You're are prepending the AWS_TYPES to the schema which is fine if you don't have these types defined in your schema. However if you have lint on your schema you will have errors if you don't define the AWS_TYPES. Can you make including types optional or remove them.

@bboure
Copy link
Collaborator

bboure commented Jun 8, 2023

You should not add those declarations in your schema, they are internal to AppSync and should not be uploaded.
I understand that you're doing this for lining purposes.
I also add them in the schema to validate them, then I remove them (They never hit AppSync).

I'd try to see if you can configure your linter to use external declarations somewhere.

What are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants