diff --git a/packages/appsync-modelgen-plugin/API.md b/packages/appsync-modelgen-plugin/API.md index 803cb2dc2..7d3a4d3be 100644 --- a/packages/appsync-modelgen-plugin/API.md +++ b/packages/appsync-modelgen-plugin/API.md @@ -25,18 +25,6 @@ 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; - // @public (undocumented) export type AssociationBaseType = { connectionType: CodeGenConnectionType; @@ -84,7 +72,6 @@ export type Field = { isArrayNullable?: boolean; attributes?: FieldAttribute[]; association?: AssociationType; - arguments?: Arguments; }; // @public (undocumented) @@ -116,9 +103,6 @@ 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 @@ -158,12 +142,6 @@ export type SchemaModel = { // @public (undocumented) export type SchemaModels = Record; -// @public (undocumented) -export type SchemaMutation = SchemaQuery; - -// @public (undocumented) -export type SchemaMutations = Record; - // @public (undocumented) export type SchemaNonModel = { name: string; @@ -173,18 +151,6 @@ export type SchemaNonModel = { // @public (undocumented) export type SchemaNonModels = Record; -// @public (undocumented) -export type SchemaQueries = Record; - -// @public (undocumented) -export type SchemaQuery = Pick; - -// @public (undocumented) -export type SchemaSubscription = SchemaQuery; - -// @public (undocumented) -export type SchemaSubscriptions = Record; - // @public (undocumented) export type Target = 'java' | 'swift' | 'javascript' | 'typescript' | 'dart' | 'introspection'; diff --git a/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json b/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json index bc8428316..d0868ecdd 100644 --- a/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json +++ b/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json @@ -14,15 +14,6 @@ }, "enums": { "$ref": "#/definitions/SchemaEnums" - }, - "queries": { - "$ref": "#/definitions/SchemaQueries" - }, - "mutations": { - "$ref": "#/definitions/SchemaMutations" - }, - "subscriptions": { - "$ref": "#/definitions/SchemaSubscriptions" } }, "required": [ @@ -131,9 +122,6 @@ }, "association": { "$ref": "#/definitions/AssociationType" - }, - "arguments": { - "$ref": "#/definitions/Arguments" } }, "required": [ @@ -329,42 +317,6 @@ "targetNames" ] }, - "Arguments": { - "$ref": "#/definitions/Record%3Cstring%2CArgument%3E" - }, - "Record": { - "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": { @@ -440,72 +392,6 @@ "values" ], "additionalProperties": false - }, - "SchemaQueries": { - "$ref": "#/definitions/Record%3Cstring%2CSchemaQuery%3E" - }, - "Record": { - "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": { - "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": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/SchemaMutation" - } - }, - "SchemaMutation": { - "$ref": "#/definitions/SchemaQuery" - }, - "SchemaSubscriptions": { - "$ref": "#/definitions/Record%3Cstring%2CSchemaSubscription%3E" - }, - "Record": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/SchemaSubscription" - } - }, - "SchemaSubscription": { - "$ref": "#/definitions/SchemaQuery" } } } diff --git a/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts index a2c354ff0..a3660dde6 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts @@ -246,7 +246,7 @@ describe('processIndex', () => { arguments: { name: 'testModelsByConnectionFieldAndSortField', fields: ['connectionField', 'sortField'], - queryField: undefined, + queryField: undefined, }, }, { diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap index b94c5399c..41f9936af 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap @@ -1612,179 +1612,6 @@ 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, diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts index bb2dab2ab..9c2c51fde 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts @@ -318,35 +318,6 @@ describe('schemas with pk on a belongsTo fk', () => { }); }); -describe('Custom queries/mutations/subscriptions tests', () => { - const schema = /* GraphQL */ ` - type Todo @model { - id: ID! - name: String! - description: String - } - type Phone { - number: String - } - type Query { - echo(msg: String): String - echo2(todoId: ID!): Todo - echo3: [Todo] - echo4(number: String): Phone - } - type Mutation { - mutate(msg: [String!]!): Todo - } - type Subscription { - onMutate(msg: String): [Todo!] - } - `; - it('should generate correct metadata for custom queries/mutations/subscriptions in model introspection schema', () => { - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); - expect(visitor.generate()).toMatchSnapshot(); - }); -}); - describe('custom fields', () => { test('sets the association for fields for hasOne', () => { const schema = /* GraphQL */ ` diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts index a59eccfbf..0b28100fb 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts @@ -1867,7 +1867,7 @@ describe('AppSyncSwiftVisitor', () => { `); }); - it('should support changing identityClaim', () => { + it('should support changing identityClaim ', () => { const schema = /* GraphQL */ ` type Post @model @auth(rules: [{ allow: owner, ownerField: "author", identityClaim: "sub" }]) { id: ID! @@ -2424,7 +2424,7 @@ describe('AppSyncSwiftVisitor', () => { `); }); - it('should support changing groupsClaim', () => { + it('should support changing groupsClaim ', () => { const schema = /* GraphQL */ ` type Post @model @auth(rules: [{ allow: groups, groups: ["admin"], groupClaim: "custom:groups" }]) { id: ID! diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts index 073002185..9b24f6397 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts @@ -194,7 +194,7 @@ describe('AppSyncModelVisitor', () => { expect(notRequiredVersion).not.toBe(requiredVersion); }); - describe('2 Way Connection', () => { + describe(' 2 Way Connection', () => { describe('with connection name', () => { const schema = /* GraphQL */ ` type Post @model { @@ -1233,7 +1233,7 @@ describe('AppSyncModelVisitor', () => { expect(() => createAndGeneratePipelinedTransformerVisitor(schema)).not.toThrow(); }); }); - + describe('Connected models with custom primary key testing', () => { it('should have correct output for hasOne and belongsTo connection info when model pk is compostie key', () => { const schema = /* GraphQL*/ ` diff --git a/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts b/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts index aea3f33b3..4321fd250 100644 --- a/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts +++ b/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts @@ -6,9 +6,6 @@ models: SchemaModels; nonModels: SchemaNonModels; enums: SchemaEnums; - queries?: SchemaQueries; - mutations?: SchemaMutations; - subscriptions?: SchemaSubscriptions; }; /** * Top-level Entities on a Schema @@ -16,9 +13,6 @@ export type SchemaModels = Record; export type SchemaNonModels = Record; export type SchemaEnums = Record; -export type SchemaQueries = Record; -export type SchemaMutations = Record; -export type SchemaSubscriptions = Record; export type SchemaModel = { name: string; @@ -36,9 +30,6 @@ export type SchemaEnum = { name: string; values: string[]; }; -export type SchemaQuery = Pick; -export type SchemaMutation = SchemaQuery; -export type SchemaSubscription = SchemaQuery; export type ModelAttribute = { type: string; properties?: {[key: string]: any} }; /** @@ -54,7 +45,6 @@ export type Field = { isArrayNullable?: boolean; attributes?: FieldAttribute[]; association?: AssociationType; - arguments?: Arguments; }; export type FieldType = 'ID' | 'String' @@ -108,12 +98,4 @@ export type PrimaryKeyInfo = { isCustomPrimaryKey: boolean; primaryKeyFieldName: string; sortKeyFieldNames: string[]; -}; -export type Arguments = Record; -export type Argument = { - name: string; - type: FieldType; - isArray: boolean; - isRequired: boolean; - isArrayNullable?: boolean; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts index 9b1e645de..d67208921 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-model-introspection-visitor.ts @@ -1,9 +1,9 @@ import { DEFAULT_SCALARS, NormalizedScalarsMap } from "@graphql-codegen/visitor-plugin-common"; import { GraphQLSchema } from "graphql"; -import { Argument, AssociationType, Field, Fields, FieldType, ModelAttribute, ModelIntrospectionSchema, PrimaryKeyInfo, SchemaEnum, SchemaModel, SchemaMutation, SchemaNonModel, SchemaQuery, SchemaSubscription } from "../interfaces/introspection"; +import { AssociationType, Field, Fields, FieldType, ModelAttribute, ModelIntrospectionSchema, PrimaryKeyInfo, SchemaEnum, SchemaModel, SchemaNonModel } from "../interfaces/introspection"; import { METADATA_SCALAR_MAP } from "../scalars"; import { CodeGenConnectionType } from "../utils/process-connections"; -import { RawAppSyncModelConfig, ParsedAppSyncModelConfig, AppSyncModelVisitor, CodeGenEnum, CodeGenField, CodeGenModel, CodeGenPrimaryKeyType, CodeGenQuery, CodeGenSubscription, CodeGenMutation } from "./appsync-visitor"; +import { RawAppSyncModelConfig, ParsedAppSyncModelConfig, AppSyncModelVisitor, CodeGenEnum, CodeGenField, CodeGenModel, CodeGenPrimaryKeyType } from "./appsync-visitor"; import fs from 'fs'; import path from 'path'; import Ajv from 'ajv'; @@ -47,7 +47,7 @@ export class AppSyncModelIntrospectionVisitor< } protected generateModelIntrospectionSchema(): ModelIntrospectionSchema { - let result: ModelIntrospectionSchema = { + const result: ModelIntrospectionSchema = { version: this.introspectionVersion, models: {}, enums: {}, @@ -63,26 +63,7 @@ export class AppSyncModelIntrospectionVisitor< const enums = Object.values(this.enumMap).reduce((acc, enumObj) => { return { ...acc, [this.getEnumName(enumObj)]: this.generateEnumMetadata(enumObj) }; }, {}); - result = { ...result, models, nonModels, enums }; - const queries = Object.values(this.queryMap).reduce((acc, queryObj: CodeGenQuery) => { - return { ...acc, [queryObj.name]: this.generateGraphQLOperationMetadata(queryObj) }; - }, {}) - const mutations = Object.values(this.mutationMap).reduce((acc, mutationObj: CodeGenMutation) => { - return { ...acc, [mutationObj.name]: this.generateGraphQLOperationMetadata(mutationObj) }; - }, {}); - const subscriptions = Object.values(this.subscriptionMap).reduce((acc, subscriptionObj: CodeGenSubscription) => { - return { ...acc, [subscriptionObj.name]: this.generateGraphQLOperationMetadata(subscriptionObj) }; - }, {}) - if(Object.keys(queries).length > 0) { - result = { ...result, queries }; - } - if(Object.keys(mutations).length > 0) { - result = { ...result, mutations }; - } - if(Object.keys(subscriptions).length > 0) { - result = { ...result, subscriptions }; - } - return result; + return { ...result, models, nonModels, enums }; } private getFieldAssociation(field: CodeGenField): AssociationType | void { @@ -152,37 +133,6 @@ export class AppSyncModelIntrospectionVisitor< values: Object.values(enumObj.values), }; } - /** - * Generate GraqhQL operation (query/mutation/subscription) metadata in model introspection schema from the codegen MIPR - * @param operationObj operation object - * @returns operation metadata in model introspection schema - */ - private generateGraphQLOperationMetadata(operationObj: T): V { - const operationMeta = { - name: operationObj.name, - isArray: operationObj.isList, - type: this.getType(operationObj.type), - isRequired: !operationObj.isNullable, - } - if (operationObj.isListNullable !== undefined) { - (operationMeta as V).isArrayNullable = operationObj.isListNullable; - } - if (operationObj.parameters && operationObj.parameters.length > 0) { - (operationMeta as V).arguments = operationObj.parameters.reduce((acc, param ) => { - const arg: Argument = { - name: param.name, - isArray: param.isList, - type: this.getType(param.type), - isRequired: !param.isNullable - }; - if (param.isListNullable !== undefined) { - arg.isArrayNullable = param.isListNullable; - } - return { ...acc, [param.name]: arg }; - }, {}) - } - return operationMeta as V; - } protected getType(gqlType: string): FieldType { // Todo: Handle unlisted scalars diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index 34c2de3f5..fc2e47ca4 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -20,7 +20,6 @@ import { ObjectTypeDefinitionNode, parse, valueFromASTUntyped, - InputValueDefinitionNode, } from 'graphql'; import { addFieldToModel, getModelPrimaryKeyComponentFields, removeFieldFromModel, toCamelCase } from '../utils/fieldUtils'; import { getTypeInfo } from '../utils/get-type-info'; @@ -187,17 +186,10 @@ export type CodeGenFieldDirective = CodeGenDirective & { fieldName: string; }; -export type CodeGenInputValue = TypeInfo & { - name: string; - directives: CodeGenDirectives; -} - export type CodeGenDirectives = CodeGenDirective[]; -export type CodeGenInputValues = CodeGenInputValue[]; export type CodeGenField = TypeInfo & { name: string; directives: CodeGenDirectives; - parameters?: CodeGenInputValues; connectionInfo?: CodeGenFieldConnection; isReadOnly?: boolean; primaryKeyInfo?: CodeGenPrimaryKeyFieldInfo; @@ -238,20 +230,6 @@ export type CodeGenEnumValueMap = { [enumConvertedName: string]: string }; export type CodeGenEnumMap = Record; -// Types for custom query/mutation/subscription -export type CodeGenQuery = CodeGenField & { - operationType: 'query'; -}; -export type CodeGenQueryMap = Record; -export type CodeGenMutation = CodeGenField & { - operationType: 'mutation'; -}; -export type CodeGenMutationMap = Record; -export type CodeGenSubscription = CodeGenField & { - operationType: 'subscription'; -}; -export type CodeGenSubscriptionMap = Record; - // Used to simplify processing of manyToMany into composing directives hasMany and belongsTo type ManyToManyContext = { model: CodeGenModel; @@ -268,9 +246,6 @@ export class AppSyncModelVisitor< protected modelMap: CodeGenModelMap = {}; protected nonModelMap: CodeGenModelMap = {}; protected enumMap: CodeGenEnumMap = {}; - protected queryMap: CodeGenQueryMap = {}; - protected mutationMap: CodeGenMutationMap = {}; - protected subscriptionMap: CodeGenSubscriptionMap = {}; protected typesToSkip: string[] = []; constructor( protected _schema: GraphQLSchema, @@ -303,12 +278,15 @@ export class AppSyncModelVisitor< }); } - this.typesToSkip = []; + this.typesToSkip = [this._schema.getQueryType(), this._schema.getMutationType(), this._schema.getSubscriptionType()] + .filter(t => t) + .map(t => (t && t.name) || ''); this.typesToSkip.push(...typesUsedInDirectives); } ObjectTypeDefinition(node: ObjectTypeDefinitionNode, index?: string | number, parent?: any) { if (this.typesToSkip.includes(node.name.value)) { + // Skip Query, mutation and subscription type return; } const directives = this.getDirectives(node.directives); @@ -333,32 +311,7 @@ export class AppSyncModelVisitor< this.addTimestampFields(model, modelDirective); this.sortFields(model); this.modelMap[node.name.value] = model; - } - else if (node.name.value === this._schema.getQueryType()?.name) { - fields.forEach(field => { - this.queryMap[field.name] = { - ...field, - operationType: 'query', - } - }); - } - else if (node.name.value === this._schema.getMutationType()?.name) { - fields.forEach(field => { - this.mutationMap[field.name] = { - ...field, - operationType: 'mutation', - } - }); - } - else if (node.name.value === this._schema.getSubscriptionType()?.name) { - fields.forEach(field => { - this.subscriptionMap[field.name] = { - ...field, - operationType: 'subscription', - } - }); - } - else { + } else { const nonModel: CodeGenModel = { name: node.name.value, type: 'model', @@ -371,24 +324,13 @@ export class AppSyncModelVisitor< FieldDefinition(node: FieldDefinitionNode): CodeGenField { const directive = this.getDirectives(node.directives); - const parameters = ((node.arguments as unknown) as CodeGenInputValue[]) ?? []; return { name: node.name.value, directives: directive, ...getTypeInfo(node.type, this._schema), - parameters, }; } - InputValueDefinition(node: InputValueDefinitionNode): CodeGenInputValue { - const directives = this.getDirectives(node.directives); - return { - name: node.name.value, - directives, - ...getTypeInfo(node.type, this._schema), - } - } - EnumTypeDefinition(node: EnumTypeDefinitionNode): void { if (this.typesToSkip.includes(node.name.value)) { // Skip Query, mutation and subscription type and additional