Skip to content

Commit 98b4243

Browse files
authored
feat(introspection): add metadata for custom GraphQL operations (#771)
* feat(introspection): add metadata for custom queries/mutations/subscriptions * fix api extract
1 parent d794391 commit 98b4243

File tree

10 files changed

+491
-15
lines changed

10 files changed

+491
-15
lines changed

packages/appsync-modelgen-plugin/API.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ export interface AppSyncModelPluginConfig extends RawDocumentsConfig {
2525
directives?: string;
2626
}
2727

28+
// @public (undocumented)
29+
export type Argument = {
30+
name: string;
31+
type: FieldType;
32+
isArray: boolean;
33+
isRequired: boolean;
34+
isArrayNullable?: boolean;
35+
};
36+
37+
// @public (undocumented)
38+
export type Arguments = Record<string, Argument>;
39+
2840
// @public (undocumented)
2941
export type AssociationBaseType = {
3042
connectionType: CodeGenConnectionType;
@@ -72,6 +84,7 @@ export type Field = {
7284
isArrayNullable?: boolean;
7385
attributes?: FieldAttribute[];
7486
association?: AssociationType;
87+
arguments?: Arguments;
7588
};
7689

7790
// @public (undocumented)
@@ -103,6 +116,9 @@ export type ModelIntrospectionSchema = {
103116
models: SchemaModels;
104117
nonModels: SchemaNonModels;
105118
enums: SchemaEnums;
119+
queries?: SchemaQueries;
120+
mutations?: SchemaMutations;
121+
subscriptions?: SchemaSubscriptions;
106122
};
107123

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

161+
// @public (undocumented)
162+
export type SchemaMutation = SchemaQuery;
163+
164+
// @public (undocumented)
165+
export type SchemaMutations = Record<string, SchemaMutation>;
166+
145167
// @public (undocumented)
146168
export type SchemaNonModel = {
147169
name: string;
@@ -151,6 +173,18 @@ export type SchemaNonModel = {
151173
// @public (undocumented)
152174
export type SchemaNonModels = Record<string, SchemaNonModel>;
153175

176+
// @public (undocumented)
177+
export type SchemaQueries = Record<string, SchemaQuery>;
178+
179+
// @public (undocumented)
180+
export type SchemaQuery = Pick<Field, 'name' | 'type' | 'isArray' | 'isRequired' | 'isArrayNullable' | 'arguments'>;
181+
182+
// @public (undocumented)
183+
export type SchemaSubscription = SchemaQuery;
184+
185+
// @public (undocumented)
186+
export type SchemaSubscriptions = Record<string, SchemaSubscription>;
187+
154188
// @public (undocumented)
155189
export type Target = 'java' | 'swift' | 'javascript' | 'typescript' | 'dart' | 'introspection';
156190

packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
},
1515
"enums": {
1616
"$ref": "#/definitions/SchemaEnums"
17+
},
18+
"queries": {
19+
"$ref": "#/definitions/SchemaQueries"
20+
},
21+
"mutations": {
22+
"$ref": "#/definitions/SchemaMutations"
23+
},
24+
"subscriptions": {
25+
"$ref": "#/definitions/SchemaSubscriptions"
1726
}
1827
},
1928
"required": [
@@ -122,6 +131,9 @@
122131
},
123132
"association": {
124133
"$ref": "#/definitions/AssociationType"
134+
},
135+
"arguments": {
136+
"$ref": "#/definitions/Arguments"
125137
}
126138
},
127139
"required": [
@@ -317,6 +329,42 @@
317329
"targetNames"
318330
]
319331
},
332+
"Arguments": {
333+
"$ref": "#/definitions/Record%3Cstring%2CArgument%3E"
334+
},
335+
"Record<string,Argument>": {
336+
"type": "object",
337+
"additionalProperties": {
338+
"$ref": "#/definitions/Argument"
339+
}
340+
},
341+
"Argument": {
342+
"type": "object",
343+
"properties": {
344+
"name": {
345+
"type": "string"
346+
},
347+
"type": {
348+
"$ref": "#/definitions/FieldType"
349+
},
350+
"isArray": {
351+
"type": "boolean"
352+
},
353+
"isRequired": {
354+
"type": "boolean"
355+
},
356+
"isArrayNullable": {
357+
"type": "boolean"
358+
}
359+
},
360+
"required": [
361+
"name",
362+
"type",
363+
"isArray",
364+
"isRequired"
365+
],
366+
"additionalProperties": false
367+
},
320368
"PrimaryKeyInfo": {
321369
"type": "object",
322370
"properties": {
@@ -392,6 +440,72 @@
392440
"values"
393441
],
394442
"additionalProperties": false
443+
},
444+
"SchemaQueries": {
445+
"$ref": "#/definitions/Record%3Cstring%2CSchemaQuery%3E"
446+
},
447+
"Record<string,SchemaQuery>": {
448+
"type": "object",
449+
"additionalProperties": {
450+
"$ref": "#/definitions/SchemaQuery"
451+
}
452+
},
453+
"SchemaQuery": {
454+
"$ref": "#/definitions/Pick%3CField%2C(%22name%22%7C%22type%22%7C%22isArray%22%7C%22isRequired%22%7C%22isArrayNullable%22%7C%22arguments%22)%3E"
455+
},
456+
"Pick<Field,(\"name\"|\"type\"|\"isArray\"|\"isRequired\"|\"isArrayNullable\"|\"arguments\")>": {
457+
"type": "object",
458+
"properties": {
459+
"name": {
460+
"type": "string"
461+
},
462+
"type": {
463+
"$ref": "#/definitions/FieldType"
464+
},
465+
"isArray": {
466+
"type": "boolean"
467+
},
468+
"isRequired": {
469+
"type": "boolean"
470+
},
471+
"isArrayNullable": {
472+
"type": "boolean"
473+
},
474+
"arguments": {
475+
"$ref": "#/definitions/Arguments"
476+
}
477+
},
478+
"required": [
479+
"name",
480+
"type",
481+
"isArray",
482+
"isRequired"
483+
],
484+
"additionalProperties": false
485+
},
486+
"SchemaMutations": {
487+
"$ref": "#/definitions/Record%3Cstring%2CSchemaMutation%3E"
488+
},
489+
"Record<string,SchemaMutation>": {
490+
"type": "object",
491+
"additionalProperties": {
492+
"$ref": "#/definitions/SchemaMutation"
493+
}
494+
},
495+
"SchemaMutation": {
496+
"$ref": "#/definitions/SchemaQuery"
497+
},
498+
"SchemaSubscriptions": {
499+
"$ref": "#/definitions/Record%3Cstring%2CSchemaSubscription%3E"
500+
},
501+
"Record<string,SchemaSubscription>": {
502+
"type": "object",
503+
"additionalProperties": {
504+
"$ref": "#/definitions/SchemaSubscription"
505+
}
506+
},
507+
"SchemaSubscription": {
508+
"$ref": "#/definitions/SchemaQuery"
395509
}
396510
}
397511
}

packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ describe('processIndex', () => {
246246
arguments: {
247247
name: 'testModelsByConnectionFieldAndSortField',
248248
fields: ['connectionField', 'sortField'],
249-
queryField: undefined,
249+
queryField: undefined,
250250
},
251251
},
252252
{

packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,179 @@ exports[`Custom primary key tests should generate correct model intropection fil
16121612
}"
16131613
`;
16141614

1615+
exports[`Custom queries/mutations/subscriptions tests should generate correct metadata for custom queries/mutations/subscriptions in model introspection schema 1`] = `
1616+
"{
1617+
\\"version\\": 1,
1618+
\\"models\\": {
1619+
\\"Todo\\": {
1620+
\\"name\\": \\"Todo\\",
1621+
\\"fields\\": {
1622+
\\"id\\": {
1623+
\\"name\\": \\"id\\",
1624+
\\"isArray\\": false,
1625+
\\"type\\": \\"ID\\",
1626+
\\"isRequired\\": true,
1627+
\\"attributes\\": []
1628+
},
1629+
\\"name\\": {
1630+
\\"name\\": \\"name\\",
1631+
\\"isArray\\": false,
1632+
\\"type\\": \\"String\\",
1633+
\\"isRequired\\": true,
1634+
\\"attributes\\": []
1635+
},
1636+
\\"description\\": {
1637+
\\"name\\": \\"description\\",
1638+
\\"isArray\\": false,
1639+
\\"type\\": \\"String\\",
1640+
\\"isRequired\\": false,
1641+
\\"attributes\\": []
1642+
},
1643+
\\"createdAt\\": {
1644+
\\"name\\": \\"createdAt\\",
1645+
\\"isArray\\": false,
1646+
\\"type\\": \\"AWSDateTime\\",
1647+
\\"isRequired\\": false,
1648+
\\"attributes\\": [],
1649+
\\"isReadOnly\\": true
1650+
},
1651+
\\"updatedAt\\": {
1652+
\\"name\\": \\"updatedAt\\",
1653+
\\"isArray\\": false,
1654+
\\"type\\": \\"AWSDateTime\\",
1655+
\\"isRequired\\": false,
1656+
\\"attributes\\": [],
1657+
\\"isReadOnly\\": true
1658+
}
1659+
},
1660+
\\"syncable\\": true,
1661+
\\"pluralName\\": \\"Todos\\",
1662+
\\"attributes\\": [
1663+
{
1664+
\\"type\\": \\"model\\",
1665+
\\"properties\\": {}
1666+
}
1667+
],
1668+
\\"primaryKeyInfo\\": {
1669+
\\"isCustomPrimaryKey\\": false,
1670+
\\"primaryKeyFieldName\\": \\"id\\",
1671+
\\"sortKeyFieldNames\\": []
1672+
}
1673+
}
1674+
},
1675+
\\"enums\\": {},
1676+
\\"nonModels\\": {
1677+
\\"Phone\\": {
1678+
\\"name\\": \\"Phone\\",
1679+
\\"fields\\": {
1680+
\\"number\\": {
1681+
\\"name\\": \\"number\\",
1682+
\\"isArray\\": false,
1683+
\\"type\\": \\"String\\",
1684+
\\"isRequired\\": false,
1685+
\\"attributes\\": []
1686+
}
1687+
}
1688+
}
1689+
},
1690+
\\"queries\\": {
1691+
\\"echo\\": {
1692+
\\"name\\": \\"echo\\",
1693+
\\"isArray\\": false,
1694+
\\"type\\": \\"String\\",
1695+
\\"isRequired\\": false,
1696+
\\"arguments\\": {
1697+
\\"msg\\": {
1698+
\\"name\\": \\"msg\\",
1699+
\\"isArray\\": false,
1700+
\\"type\\": \\"String\\",
1701+
\\"isRequired\\": false
1702+
}
1703+
}
1704+
},
1705+
\\"echo2\\": {
1706+
\\"name\\": \\"echo2\\",
1707+
\\"isArray\\": false,
1708+
\\"type\\": {
1709+
\\"model\\": \\"Todo\\"
1710+
},
1711+
\\"isRequired\\": false,
1712+
\\"arguments\\": {
1713+
\\"todoId\\": {
1714+
\\"name\\": \\"todoId\\",
1715+
\\"isArray\\": false,
1716+
\\"type\\": \\"ID\\",
1717+
\\"isRequired\\": true
1718+
}
1719+
}
1720+
},
1721+
\\"echo3\\": {
1722+
\\"name\\": \\"echo3\\",
1723+
\\"isArray\\": true,
1724+
\\"type\\": {
1725+
\\"model\\": \\"Todo\\"
1726+
},
1727+
\\"isRequired\\": false,
1728+
\\"isArrayNullable\\": true
1729+
},
1730+
\\"echo4\\": {
1731+
\\"name\\": \\"echo4\\",
1732+
\\"isArray\\": false,
1733+
\\"type\\": {
1734+
\\"nonModel\\": \\"Phone\\"
1735+
},
1736+
\\"isRequired\\": false,
1737+
\\"arguments\\": {
1738+
\\"number\\": {
1739+
\\"name\\": \\"number\\",
1740+
\\"isArray\\": false,
1741+
\\"type\\": \\"String\\",
1742+
\\"isRequired\\": false
1743+
}
1744+
}
1745+
}
1746+
},
1747+
\\"mutations\\": {
1748+
\\"mutate\\": {
1749+
\\"name\\": \\"mutate\\",
1750+
\\"isArray\\": false,
1751+
\\"type\\": {
1752+
\\"model\\": \\"Todo\\"
1753+
},
1754+
\\"isRequired\\": false,
1755+
\\"arguments\\": {
1756+
\\"msg\\": {
1757+
\\"name\\": \\"msg\\",
1758+
\\"isArray\\": true,
1759+
\\"type\\": \\"String\\",
1760+
\\"isRequired\\": true,
1761+
\\"isArrayNullable\\": false
1762+
}
1763+
}
1764+
}
1765+
},
1766+
\\"subscriptions\\": {
1767+
\\"onMutate\\": {
1768+
\\"name\\": \\"onMutate\\",
1769+
\\"isArray\\": true,
1770+
\\"type\\": {
1771+
\\"model\\": \\"Todo\\"
1772+
},
1773+
\\"isRequired\\": true,
1774+
\\"isArrayNullable\\": true,
1775+
\\"arguments\\": {
1776+
\\"msg\\": {
1777+
\\"name\\": \\"msg\\",
1778+
\\"isArray\\": false,
1779+
\\"type\\": \\"String\\",
1780+
\\"isRequired\\": false
1781+
}
1782+
}
1783+
}
1784+
}
1785+
}"
1786+
`;
1787+
16151788
exports[`Model Introspection Visitor Metadata snapshot should generate correct model intropection file validated by JSON schema 1`] = `
16161789
"{
16171790
\\"version\\": 1,

0 commit comments

Comments
 (0)