Skip to content

Commit 7b15760

Browse files
authored
resolve issue #100 for type and interface (#102)
* checkout from union branch * add support for unions in graphql-resolver-generator * add __type name as field to created edges and types * update changelog
1 parent 0e1adbf commit 7b15760

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
**v0.1.4, to be released on ???**
22
* New feature: Add support for unions. See: https://github.com/LiUGraphQL/woo.sh/issues/95
3+
* New feature: Encode the typename as part of the inserted object. See: https://github.com/LiUGraphQL/woo.sh/issues/100
34

45
**v0.1.3, released on August 28, 2020**
56
* New feature: Support for multiple *dependent* mutation operations within a single mutation request; https://github.com/LiUGraphQL/woo.sh/issues/52

graphql-api-generator/utils/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ def print_schema_with_directives(schema):
12161216
:return string:
12171217
"""
12181218
manual_directives = {
1219-
'export': 'directive @export(as: String!) on FIELD',
12201219
'required': 'directive @required on FIELD_DEFINITION',
12211220
'key': 'directive @key(fields: [String!]!) on OBJECT | INPUT_OBJECT',
12221221
'distinct': 'directive @distinct on FIELD_DEFINITION | INPUT_FIELD_DEFINITION',

graphql-resolver-generator/generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def generate(input_file, output_dir, config: dict):
4141
continue
4242
if is_interface_type(_type):
4343
data['interfaces'].append(type_name)
44+
if is_union_type(_type):
45+
data['unions'].append(type_name)
4446
if is_edge_type(_type):
4547
if config.get('generation').get('query_edge_by_id'):
4648
data['edge_objects'].append(type_name)

graphql-resolver-generator/resources/resolver.template

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,26 @@ const resolvers = {
150150
% if interface_name.startswith('_'):
151151
${interface_name}: {
152152
__resolveType: (parent, args, context, info) =>
153-
'_' + parent._id.split('/')[0]
153+
'_' + parent.__typename
154154
},
155155
% else:
156156
${interface_name}: {
157157
__resolveType: (parent, args, context, info) =>
158-
parent._id.split('/')[0]
158+
parent.__typename
159+
},
160+
% endif
161+
% endfor
162+
163+
% for union_name in data['unions']:
164+
% if union_name.startswith('_'):
165+
${union_name}: {
166+
__resolveType: (parent, args, context, info) =>
167+
'_' + union_name.__typename
168+
},
169+
% else:
170+
${union_name}: {
171+
__resolveType: (parent, args, context, info) =>
172+
parent.__typename
159173
},
160174
% endif
161175
% endfor

graphql-server/drivers/arangodb/driver.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ function createEdge(isRoot, ctxt, varOrSourceID, sourceType, sourceField, varOrT
348348
// define doc
349349
const doc = annotations;
350350
doc['_creationDate'] = new Date().valueOf();
351+
doc['__typename'] = `_${collectionName}`;
351352
const docVar = addParameterVar(ctxt, createParamVar(ctxt), doc);
352353

353354
// validate edge
@@ -388,6 +389,7 @@ function create(isRoot, ctxt, data, returnType, info, resVar = null) {
388389
// get non-object fields, add creation date and add as parameter
389390
const doc = getScalarsAndEnums(data, returnType);
390391
doc['_creationDate'] = new Date().valueOf();
392+
doc['__typename'] = returnType.name;
391393
const docVar = addParameterVar(ctxt, createParamVar(ctxt), doc);
392394

393395
// create a new resVar if not defined by the calling function, resVar is the source vertex for all edges
@@ -643,6 +645,7 @@ function update(isRoot, ctxt, varOrID, data, returnType, info, resVar = null) {
643645
// get non-object fields, add creation date and add as parameter
644646
let doc = getScalarsAndEnums(data, returnType);
645647
doc['_lastUpdateDate'] = new Date().valueOf();
648+
doc['__typename'] = returnType.name;
646649
let docVar = addParameterVar(ctxt, createParamVar(ctxt), doc);
647650

648651
// create a new resVar if not defined by the calling function, resVar is the source vertex for all edges

0 commit comments

Comments
 (0)