Skip to content

Commit

Permalink
feat: added generating graphql interfaces as types (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
TakSeBiegam authored Aug 5, 2024
1 parent e6e26e7 commit 4c37b8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
"examples/beerpub-yoga-federated",
"examples/beerpub-apollo-server"
]
}
}
10 changes: 9 additions & 1 deletion packages/core/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ const generateModelsString = (fileContent: string) => {
})
.join('\n');

const interfaces = nodes.filter((n) => n.data.type === TypeDefinition.InterfaceTypeDefinition);
const interfacesString = interfaces
.map((i) => {
const interfaceFields = i.args.map((a) => `${resolveField(a)};`);
return `export interface ${i.name} {\n${interfaceFields.join('\n')}\n}`;
})
.join('\n');

const types = nodes.filter((n) => n.data.type === TypeDefinition.ObjectTypeDefinition);
const typesString = types
.map((t) => {
Expand Down Expand Up @@ -114,7 +122,7 @@ const generateModelsString = (fileContent: string) => {
? `export type Directives = {\n${directivesString}\n};`
: 'export type Directives = {}';
return (
[scalarsString, enumsString, inputsString, typesFullString, directivesFullString, dbTypes]
[scalarsString, enumsString, inputsString, typesFullString, directivesFullString, interfacesString, dbTypes]
.filter(Boolean)
.join('\n\n') + '\n'
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aexol/axolotl-core",
"version": "0.4.4",
"version": "0.4.5",
"private": false,
"main": "./lib/index.js",
"author": "Aexol, Artur Czemiel",
Expand Down

0 comments on commit 4c37b8b

Please sign in to comment.