def _build_stitch_directive(source_field_name, sink_field_name):
    """Build a Directive node for the stitch directive."""
    return ast_types.DirectiveNode(
        name=ast_types.NameNode(value="stitch"),
        arguments=[
            ast_types.ArgumentNode(
                name=ast_types.NameNode(value="source_field"),
                value=ast_types.StringValueNode(value=source_field_name),
            ),
            ast_types.ArgumentNode(
                name=ast_types.NameNode(value="sink_field"),
                value=ast_types.StringValueNode(value=sink_field_name),
            ),
        ],
    )
Esempio n. 2
0
 def visit_deprecated_directive(self, obj):
     return ast.DirectiveNode(
         name=_name('deprecated'),
         arguments=[
             ast.ArgumentNode(
                 name=_name('reason'),
                 value=ast.StringValueNode(value=obj.reason),
             ),
         ],
     )
Esempio n. 3
0
 def visit_requires_directive(self, obj):
     return ast.DirectiveNode(
         name=_name('requires'),
         arguments=[
             ast.ArgumentNode(
                 name=_name('fields'),
                 value=ast.StringValueNode(value=obj.fields),
             ),
         ],
     )
Esempio n. 4
0
 def visit_field(self, obj: Field):
     arguments = None
     if obj.options:
         arguments = [
             ast.ArgumentNode(name=_name(key), value=_encode(val))
             for key, val in obj.options.items()
         ]
     return ast.FieldNode(
         name=_name(obj.name),
         alias=_name(obj.alias),
         arguments=arguments,
     )
Esempio n. 5
0
 def visit_link(self, obj):
     arguments = None
     if obj.options:
         arguments = [
             ast.ArgumentNode(name=_name(key), value=_encode(val))
             for key, val in obj.options.items()
         ]
     return ast.FieldNode(
         name=_name(obj.name),
         alias=_name(obj.alias),
         arguments=arguments,
         selection_set=self.visit(obj.node),
     )
Esempio n. 6
0
    def args(self, **kwargs):
        if self.camelcase:
            self.args_to_camelcase(kwargs)
        argument_nodes = list()
        for name, value in kwargs.items():
            arg = self.field.args.get(name)
            if not arg:
                raise ValueError(f"Invalid argument {name} for field {self.name}")
            arg_type_serializer = get_arg_serializer(arg.type)
            value = arg_type_serializer(value)

            argument_nodes.append(
                ast.ArgumentNode(
                    name=ast.NameNode(value=name), value=get_ast_value(value)
                )
            )
        self.ast_field.arguments = FrozenList(argument_nodes)
        return self