Skip to content

Commit

Permalink
[FEATURE] Updated GraphQl Enpoint snippet with correct Mutation Input
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisvoncken committed Mar 5, 2021
1 parent e7fccb7 commit a8f3122
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
14 changes: 12 additions & 2 deletions mage2gen/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,13 @@ def __init__(self, item_identifier, **kwargs):
self.item_arguments = kwargs.get('item_arguments', '')
self.item_resolver = kwargs.get('item_resolver', '')
self.item_description = kwargs.get('description', '')
self.item_input = kwargs.get('item_input', '')
self.base_type = kwargs.get('base_type', '')
if self.item_description:
self.item_description = '@doc(description: "Query by {}.")'.format(self.item_description)
if self.base_type == 'Mutation':
self.item_description = '@doc(description: "Input {}.")'.format(self.item_description)
else:
self.item_description = '@doc(description: "Query by {}.")'.format(self.item_description)
self.item_cache_identity = kwargs.get('item_cache_identity', '')
self.body = [kwargs.get('body', '')]
self.end_body = [kwargs.get('end_body', '')]
Expand All @@ -508,8 +513,13 @@ def __init__(self, item_identifier, **kwargs):
if self.item_arguments:
arguments = []
for argument in self.item_arguments.split(','):
arguments.append('\t\t\t{argument}: String @doc(description: "Query by {argument}.")'.format(argument=argument))
if self.base_type == 'Mutation':
arguments.append('\t\t\t{argument}: String @doc(description: "Input {argument}.")'.format(argument=argument))
else:
arguments.append('\t\t\t{argument}: String @doc(description: "Query by {argument}.")'.format(argument=argument))
self.item_arguments = '(\n' + ",\n".join(arguments) + '\n\t)'
if self.item_input:
self.item_arguments = '(input: {item_input})'.format(item_input=self.item_input)

def __eq__(self, other):
return self.item_identifier == other.item_identifier
Expand Down
16 changes: 13 additions & 3 deletions mage2gen/snippets/graphqlendpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def add(self, base_type, identifier, custom_type=False, description='', object_a
if base_type == 'Query':
item_type = item_identifier

if base_type == 'Mutation':
item_identifier = '{}Input'.format(item_identifier)
item_type = item_identifier
if not object_arguments:
object_arguments = 'id'
object_fields = object_arguments

schema = GraphQlSchema()

if base_type != 'Custom':
Expand All @@ -105,7 +112,9 @@ def add(self, base_type, identifier, custom_type=False, description='', object_a
item_type=item_type,
item_resolver=resolver_graphqlformat,
item_cache_identity=cache_identity_graphqlformat,
description=description
description=description,
item_input= item_type if base_type == 'Mutation' else False,
base_type=base_type
)
)

Expand All @@ -121,11 +130,12 @@ def add(self, base_type, identifier, custom_type=False, description='', object_a
item_definition.add_objectitem(
GraphQlObjectItem(
object_field,
description=object_field
description=object_field,
base_type=base_type
)
)

if base_type != 'Mutation':
if object_arguments:
schema.add_objecttype(
item_definition
)
Expand Down

0 comments on commit a8f3122

Please sign in to comment.