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

feat(introspection): add metadata for custom GraphQL operations #771

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/appsync-modelgen-plugin/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ export interface AppSyncModelPluginConfig extends RawDocumentsConfig {
directives?: string;
}

// @public (undocumented)
export type Argument = {
name: string;
type: FieldType;
isArray: boolean;
isRequired: boolean;
isArrayNullable?: boolean;
};

// @public (undocumented)
export type Arguments = Record<string, Argument>;

// @public (undocumented)
export type AssociationBaseType = {
connectionType: CodeGenConnectionType;
Expand Down Expand Up @@ -72,6 +84,7 @@ export type Field = {
isArrayNullable?: boolean;
attributes?: FieldAttribute[];
association?: AssociationType;
arguments?: Arguments;
};

// @public (undocumented)
Expand Down Expand Up @@ -103,6 +116,9 @@ export type ModelIntrospectionSchema = {
models: SchemaModels;
nonModels: SchemaNonModels;
enums: SchemaEnums;
queries?: SchemaQueries;
mutations?: SchemaMutations;
subscriptions?: SchemaSubscriptions;
};

// Warning: (ae-forgotten-export) The symbol "RawAppSyncModelConfig" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -142,6 +158,12 @@ export type SchemaModel = {
// @public (undocumented)
export type SchemaModels = Record<string, SchemaModel>;

// @public (undocumented)
export type SchemaMutation = SchemaQuery;

// @public (undocumented)
export type SchemaMutations = Record<string, SchemaMutation>;

// @public (undocumented)
export type SchemaNonModel = {
name: string;
Expand All @@ -151,6 +173,18 @@ export type SchemaNonModel = {
// @public (undocumented)
export type SchemaNonModels = Record<string, SchemaNonModel>;

// @public (undocumented)
export type SchemaQueries = Record<string, SchemaQuery>;

// @public (undocumented)
export type SchemaQuery = Pick<Field, 'name' | 'type' | 'isArray' | 'isRequired' | 'isArrayNullable' | 'arguments'>;

// @public (undocumented)
export type SchemaSubscription = SchemaQuery;

// @public (undocumented)
export type SchemaSubscriptions = Record<string, SchemaSubscription>;

// @public (undocumented)
export type Target = 'java' | 'swift' | 'javascript' | 'typescript' | 'dart' | 'introspection';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
},
"enums": {
"$ref": "#/definitions/SchemaEnums"
},
"queries": {
"$ref": "#/definitions/SchemaQueries"
},
"mutations": {
"$ref": "#/definitions/SchemaMutations"
},
"subscriptions": {
"$ref": "#/definitions/SchemaSubscriptions"
}
},
"required": [
Expand Down Expand Up @@ -122,6 +131,9 @@
},
"association": {
"$ref": "#/definitions/AssociationType"
},
"arguments": {
"$ref": "#/definitions/Arguments"
}
},
"required": [
Expand Down Expand Up @@ -317,6 +329,42 @@
"targetNames"
]
},
"Arguments": {
"$ref": "#/definitions/Record%3Cstring%2CArgument%3E"
},
"Record<string,Argument>": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Argument"
}
},
"Argument": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"$ref": "#/definitions/FieldType"
},
"isArray": {
"type": "boolean"
},
"isRequired": {
"type": "boolean"
},
"isArrayNullable": {
"type": "boolean"
}
},
"required": [
"name",
"type",
"isArray",
"isRequired"
],
"additionalProperties": false
},
"PrimaryKeyInfo": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -392,6 +440,72 @@
"values"
],
"additionalProperties": false
},
"SchemaQueries": {
"$ref": "#/definitions/Record%3Cstring%2CSchemaQuery%3E"
},
"Record<string,SchemaQuery>": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/SchemaQuery"
}
},
"SchemaQuery": {
"$ref": "#/definitions/Pick%3CField%2C(%22name%22%7C%22type%22%7C%22isArray%22%7C%22isRequired%22%7C%22isArrayNullable%22%7C%22arguments%22)%3E"
},
"Pick<Field,(\"name\"|\"type\"|\"isArray\"|\"isRequired\"|\"isArrayNullable\"|\"arguments\")>": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"$ref": "#/definitions/FieldType"
},
"isArray": {
"type": "boolean"
},
"isRequired": {
"type": "boolean"
},
"isArrayNullable": {
"type": "boolean"
},
"arguments": {
"$ref": "#/definitions/Arguments"
}
},
"required": [
"name",
"type",
"isArray",
"isRequired"
],
"additionalProperties": false
},
"SchemaMutations": {
"$ref": "#/definitions/Record%3Cstring%2CSchemaMutation%3E"
},
"Record<string,SchemaMutation>": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/SchemaMutation"
}
},
"SchemaMutation": {
"$ref": "#/definitions/SchemaQuery"
},
"SchemaSubscriptions": {
"$ref": "#/definitions/Record%3Cstring%2CSchemaSubscription%3E"
},
"Record<string,SchemaSubscription>": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/SchemaSubscription"
}
},
"SchemaSubscription": {
"$ref": "#/definitions/SchemaQuery"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe('processIndex', () => {
arguments: {
name: 'testModelsByConnectionFieldAndSortField',
fields: ['connectionField', 'sortField'],
queryField: undefined,
queryField: undefined,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,179 @@ exports[`Custom primary key tests should generate correct model intropection fil
}"
`;

exports[`Custom queries/mutations/subscriptions tests should generate correct metadata for custom queries/mutations/subscriptions in model introspection schema 1`] = `
"{
\\"version\\": 1,
\\"models\\": {
\\"Todo\\": {
\\"name\\": \\"Todo\\",
\\"fields\\": {
\\"id\\": {
\\"name\\": \\"id\\",
\\"isArray\\": false,
\\"type\\": \\"ID\\",
\\"isRequired\\": true,
\\"attributes\\": []
},
\\"name\\": {
\\"name\\": \\"name\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": true,
\\"attributes\\": []
},
\\"description\\": {
\\"name\\": \\"description\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"attributes\\": []
},
\\"createdAt\\": {
\\"name\\": \\"createdAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
},
\\"updatedAt\\": {
\\"name\\": \\"updatedAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
}
},
\\"syncable\\": true,
\\"pluralName\\": \\"Todos\\",
\\"attributes\\": [
{
\\"type\\": \\"model\\",
\\"properties\\": {}
}
],
\\"primaryKeyInfo\\": {
\\"isCustomPrimaryKey\\": false,
\\"primaryKeyFieldName\\": \\"id\\",
\\"sortKeyFieldNames\\": []
}
}
},
\\"enums\\": {},
\\"nonModels\\": {
\\"Phone\\": {
\\"name\\": \\"Phone\\",
\\"fields\\": {
\\"number\\": {
\\"name\\": \\"number\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"attributes\\": []
}
}
}
},
\\"queries\\": {
\\"echo\\": {
\\"name\\": \\"echo\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"arguments\\": {
\\"msg\\": {
\\"name\\": \\"msg\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false
}
}
},
\\"echo2\\": {
\\"name\\": \\"echo2\\",
\\"isArray\\": false,
\\"type\\": {
\\"model\\": \\"Todo\\"
},
\\"isRequired\\": false,
\\"arguments\\": {
\\"todoId\\": {
\\"name\\": \\"todoId\\",
\\"isArray\\": false,
\\"type\\": \\"ID\\",
\\"isRequired\\": true
}
}
},
\\"echo3\\": {
\\"name\\": \\"echo3\\",
\\"isArray\\": true,
\\"type\\": {
\\"model\\": \\"Todo\\"
},
\\"isRequired\\": false,
\\"isArrayNullable\\": true
},
\\"echo4\\": {
\\"name\\": \\"echo4\\",
\\"isArray\\": false,
\\"type\\": {
\\"nonModel\\": \\"Phone\\"
},
\\"isRequired\\": false,
\\"arguments\\": {
\\"number\\": {
\\"name\\": \\"number\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false
}
}
}
},
\\"mutations\\": {
\\"mutate\\": {
\\"name\\": \\"mutate\\",
\\"isArray\\": false,
\\"type\\": {
\\"model\\": \\"Todo\\"
},
\\"isRequired\\": false,
\\"arguments\\": {
\\"msg\\": {
\\"name\\": \\"msg\\",
\\"isArray\\": true,
\\"type\\": \\"String\\",
\\"isRequired\\": true,
\\"isArrayNullable\\": false
}
}
}
},
\\"subscriptions\\": {
\\"onMutate\\": {
\\"name\\": \\"onMutate\\",
\\"isArray\\": true,
\\"type\\": {
\\"model\\": \\"Todo\\"
},
\\"isRequired\\": true,
\\"isArrayNullable\\": true,
\\"arguments\\": {
\\"msg\\": {
\\"name\\": \\"msg\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false
}
}
}
}
}"
`;

exports[`Model Introspection Visitor Metadata snapshot should generate correct model intropection file validated by JSON schema 1`] = `
"{
\\"version\\": 1,
Expand Down
Loading