schema:
  - ../../services/api/schemas/**/*.graphql
generates:
  ./src/codegen/API.ts:
    plugins:
      - typescript
    config:
      scalars:
        AWSDate: string
        AWSTime: string
        AWSDateTime: string
        AWSTimestamp: string
        AWSEmail: string
        AWSJSON: '{ [key: string]: any }'
        AWSURL: string
        AWSPhone: string
        AWSIPAddress: string
      namingConvention: keep
      skipTypename: true
  # DynamoDb export
  # Used to enforce consistancy on DynamoDb tables
  ./src/codegen/DB.ts:
    plugins:
      - add:
          content: |
            export type WithKeys<QueryType> = QueryType & {
              /** Object Type in ALL CAPS */
              _type: string;
              /** Partition Key */
              pk: string;
              /** Sort Key */
              sk: string;
              gsi1PK?: string;
              gsi1SK?: string;
              gsi2PK?: string;
              gsi2SK?: string;
              gsi3PK?: string;
              gsi3SK?: string;
              gsi4PK?: string;
              gsi4SK?: string;
              gsi5PK?: string;
              gsi5SK?: string;
            };

      # General typescript plugin first, but this should just setup the scalars and import the enumValues from API.ts
      - typescript:
          scalars:
            AWSDate: string
            AWSTime: string
            AWSDateTime: string
            AWSTimestamp: string
            AWSEmail: string
            AWSJSON: '{ [key: string]: any }'
            AWSURL: string
            AWSPhone: string
            AWSIPAddress: string
          namingConvention: keep
          enumValues: ./API
          onlyOperationTypes: false
          noExport: true
      - typescript-mongodb:
          scalars: # Must be duplicated due to a bug
            AWSDate: string
            AWSTime: string
            AWSDateTime: string
            AWSTimestamp: string
            AWSEmail: string
            AWSJSON: '{ [key: string]: any }'
            AWSURL: string
            AWSPhone: string
            AWSIPAddress: string
          namingConvention: keep
          objectIdType: string
          idFieldName: id
          skipTypename: false
          nonOptionalTypename: true
          enumsAsString: false
  # JSON export
  ./src/codegen/introspection.json:
    plugins:
      - introspection
