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

fix: process input object, union and interface metadata in model introspection schema codegen #795

Merged
merged 14 commits into from
Apr 3, 2024

Conversation

AaronZyLee
Copy link
Contributor

@AaronZyLee AaronZyLee commented Mar 7, 2024

Description of changes

The input, union and interface types are correctly processed by the base visitor when it is defined in the GQL schema. The union and interface IR, however, will not be processed into the output of MIS

Codegen Parameters Changed or Added

The type of model schema is changed

export type ModelIntrospectionSchema = {
  version: 1;
  models: SchemaModels;
  nonModels: SchemaNonModels;
  enums: SchemaEnums;
  queries?: SchemaQueries;
  mutations?: SchemaMutations;
  subscriptions?: SchemaSubscriptions;
  // new root level optional attribute
  inputs?: SchemaInputs 
};

// New type definitions
export type SchemaInputs = Record<string, Input>;

export type Input = {
   name: string;
   arguments: Arguments
}

// Fine-grained field type
export type ScalarType = 'ID'
  | 'String'
  | 'Int'
  | 'Float'
  | 'AWSDate'
  | 'AWSTime'
  | 'AWSDateTime'
  | 'AWSTimestamp'
  | 'AWSEmail'
  | 'AWSURL'
  | 'AWSIPAddress'
  | 'Boolean'
  | 'AWSJSON'
  | 'AWSPhone';

export type InputFieldType = ScalarType
  | { enum: string }
  | { input: string };

export type FieldType = ScalarType
  | { enum: string }
  | { model: string }
  | { nonModel: string };

// Change argument field type
export Argument = {
  ...,
  type: InputFieldType
}

Input Example

Given the GraphQL schema in SDL

input CustomInput {
    customField1: String!
    customField2: BillingSource!
    customField3: NestedInput!
}
input NestedInput {
    content: String!
}
enum BillingSource {
    CLIENT
    PROJECT
}
type Query {
  echo(myInput: CustomInput): String!
}

The corresponding part will be generated in model introspection schema

{
    "queries": {
        "echo": {
            "name": "echo",
            "isArray": false,
            "type": "String",
            "isRequired": true,
            "arguments": {
                "myInput": {
                    "name": "myInput",
                    "isArray": false,
                    "type": {
                        "input": "CustomInput"
                    },
                    "isRequired": false
                }
            }
        }
    },
    "inputs": {
        "CustomInput": {
            "name": "CustomInput",
            "arguments": {
                "customField1": {
                    "name": "customField1",
                    "isArray": false,
                    "type": "String",
                    "isRequired": true
                },
                "customField2": {
                    "name": "customField2",
                    "isArray": false,
                    "type": {
                        "enum": "BillingSource"
                    },
                    "isRequired": true
                },
                "customField3": {
                    "name": "customField3",
                    "isArray": false,
                    "type": {
                        "input": "NestedInput"
                    },
                    "isRequired": true
                }
            }
        },
        "NestedInput": {
            "name": "NestedInput",
            "arguments": {
                "content": {
                    "name": "content",
                    "isArray": false,
                    "type": "String",
                    "isRequired": true
                }
            }
        }
    },
    "enums": {
        "BillingSource": {
            "name": "BillingSource",
            "values": [
                "CLIENT",
                "PROJECT"
            ]
        }
    },
}

Union & Interface

Union and Interface types will not be generated in the MIS json file. The fields with these types will be omitted when they present in type definition. They can still be recognized as it is being processed in the base visitor

Issue #, if available

Fix #794

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • Breaking changes to existing customers are released behind a feature flag or major version update
  • Changes are tested using sample applications for all relevant platforms (iOS/android/flutter/Javascript) that use the feature added/modified
  • Changes are tested on windows. Some Node functions (such as path) behave differently on windows.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@AaronZyLee AaronZyLee requested a review from a team as a code owner March 7, 2024 22:40
@AaronZyLee AaronZyLee requested a review from a team as a code owner March 8, 2024 00:45
@AaronZyLee AaronZyLee requested a review from Jshhhh March 8, 2024 16:55
Jshhhh
Jshhhh previously approved these changes Mar 8, 2024
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change responds to the opt-in regions used for e2e tests, which is similar to the related cleanup script change in API category

@AaronZyLee AaronZyLee changed the title fix: add input object metadata in model introspection schema feat: add input object, union and interface metadata in model introspection schema Mar 20, 2024
@AaronZyLee AaronZyLee changed the title feat: add input object, union and interface metadata in model introspection schema fix: add input object, union and interface metadata in model introspection schema Mar 20, 2024
@AaronZyLee AaronZyLee changed the title fix: add input object, union and interface metadata in model introspection schema fix: process input object, union and interface metadata in model introspection schema codegen Mar 26, 2024
@dpilch dpilch mentioned this pull request Apr 1, 2024
2 tasks
Jshhhh
Jshhhh previously approved these changes Apr 2, 2024
@AaronZyLee AaronZyLee enabled auto-merge (squash) April 3, 2024 19:34
Copy link
Member

@iartemiev iartemiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granting admin approval after reviewing API.md and .codebuild/* changes. Did not review implementation changes.

@AaronZyLee AaronZyLee merged commit 73e4520 into main Apr 3, 2024
5 checks passed
@AaronZyLee AaronZyLee deleted the fix-input-type branch April 3, 2024 20:09
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

Successfully merging this pull request may close these issues.

Build fail on unknown type from GraphQL Scheme
6 participants