def input_object_type_definition(self, tree: Tree) -> GraphQLInputObjectType:
     # TODO: Add directives
     description = None
     ast_node = None  # TODO: Should we discard it or keep it ?
     name = None
     fields = None
     for child in tree.children:
         if child.type == 'description':
             description = child.value
         elif child.type == 'INPUT':
             ast_node = child
         elif child.type == 'IDENT':
             name = String(str(child.value), ast_node=child)
         elif child.type == 'input_fields':
             fields = child.value
         elif child.type == 'discard':
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLInputObjectType(
         name=name,
         fields=fields,
         description=description,
     )
    def enum_type_definition(self, tree: Tree):
        # TODO: Add directives
        description = None
        ast_node = None  # TODO: Should we discard it or keep it ?
        name = None
        values = None
        for child in tree.children:
            if child.type == 'description':
                description = child.value
            elif child.type == 'ENUM':
                ast_node = child
            elif child.type == 'IDENT':
                name = String(str(child.value), ast_node=child)
            elif child.type == 'enum_values':
                values = child.value
            elif child.type == 'discard':
                pass
            else:
                raise UnexpectedASTNode(
                    "Unexpected AST node `{}`, type `{}`".format(
                        child, child.__class__.__name__))

        return GraphQLEnumType(
            name=name,
            values=values,
            description=description,
        )
 def input_value_definition(self, tree: Tree):
     # TODO: Add directives
     description = None
     name = None
     gql_type = None
     default_value = None
     for child in tree.children:
         if child.type == 'description':
             description = child.value
         elif child.type == 'IDENT':
             name = String(str(child.value), ast_node=child)
         elif child.type == 'type':
             gql_type = child.value
         elif child.type == 'value':
             default_value = child.value
         elif child.type == 'discard':
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLArgument(
         name=name,
         gql_type=gql_type,
         default_value=default_value,
         description=description,
     )
Esempio n. 4
0
 def input_value_definition(self, tree: Tree) -> GraphQLArgument:
     # TODO: Add directives
     description = None
     name = None
     gql_type = None
     default_value = None
     directives = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "type":
             gql_type = child.value
         elif child.type == "value":
             default_value = child.value
         elif child.type == "discard":
             pass
         elif child.type == "directives":
             directives = child.value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLArgument(
         name=name,
         gql_type=gql_type,
         default_value=default_value,
         description=description,
         directives=directives,
     )
 def union_type_definition(self, tree: Tree) -> GraphQLUnionType:
     # TODO: Add directives
     description = None
     ast_node = None  # TODO: Should we discard it or keep it ?
     name = None
     members = None
     for child in tree.children:
         if child.type == 'description':
             description = child.value
         elif child.type == 'UNION':
             ast_node = child
         elif child.type == 'IDENT':
             name = String(str(child.value), ast_node=child)
         elif child.type == 'union_members':
             members = child.value
         elif child.type == 'discard':
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLUnionType(
         name=name,
         gql_types=members,
         description=description,
     )
 def union_type_definition(self, tree: Tree) -> GraphQLUnionType:
     description = None
     name = None
     members = None
     directives = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "union_members":
             members = child.value
         elif child.type == "directives":
             directives = child.value
         elif child.type == "discard" or child.type == "UNION":
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLUnionType(
         name=name,
         gql_types=members,
         description=description,
         schema=self._schema,
         directives=directives,
     )
Esempio n. 7
0
 def directive_definition(self, tree: Tree) -> Tree:
     description = None
     name = None
     applies_on = None
     arguments = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "arguments":
             arguments = child.value
         elif child.type == "ON":
             pass
         elif child.type == "directive_locations":
             applies_on = child.value
         elif child.type == "discard" or child.type == "DIRECTIVE":
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     directive = GraphQLDirective(
         name=name,
         on=applies_on,
         arguments=arguments,
         description=description,
     )
     self._schema.add_directive(directive)
     return Tree("directive_definition", [directive])
Esempio n. 8
0
 def input_object_type_definition(self,
                                  tree: Tree) -> GraphQLInputObjectType:
     # TODO: Add directives
     description = None
     name = None
     fields = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "input_fields":
             fields = child.value
         elif child.type == "discard" or child.type == "INPUT":
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLInputObjectType(
         name=name,
         fields=fields,
         description=description,
         schema=self._schema,
     )
Esempio n. 9
0
 def field_definition(self, tree: Tree) -> GraphQLField:
     description = None
     name = None
     arguments = None
     gql_type = None
     directives = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "type":
             gql_type = child.value
         elif child.type == "arguments":
             arguments = child.value
         elif child.type == "directives":
             directives = child.value
         elif child.type == "discard":
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLField(
         name=name,
         gql_type=gql_type,
         arguments=arguments,
         description=description,
         directives=directives,
         schema=self._schema,
     )
Esempio n. 10
0
    def enum_type_definition(self, tree: Tree) -> GraphQLEnumType:
        # TODO: Add directives
        description = None
        name = None
        values = None
        for child in tree.children:
            if child.type == "description":
                description = child.value
            elif child.type == "IDENT":
                name = child.value
            elif child.type == "enum_values":
                values = child.value
            elif child.type == "discard" or child.type == "ENUM":
                pass
            else:
                raise UnexpectedASTNode(
                    "Unexpected AST node `{}`, type `{}`".format(
                        child, child.__class__.__name__))

        enum_type = GraphQLEnumType(
            name=name,
            values=values,
            description=description,
            schema=self._schema,
        )
        self._schema.add_enum_definition(enum_type)
        return enum_type
 def object_type_definition(self, tree: Tree) -> GraphQLObjectType:
     description = None
     name = None
     interfaces = None
     fields = None
     directives = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "interfaces":
             interfaces = child.value
         elif child.type == "directives":
             directives = child.value
         elif child.type == "fields":
             fields = child.value
         elif child.type == "discard" or child.type == "TYPE":
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLObjectType(
         name=name,
         fields=fields,
         interfaces=interfaces,
         description=description,
         schema=self._schema,
         directives=directives,
     )
 def field_definition(self, tree: Tree) -> GraphQLField:
     # TODO: Add directives
     description = None
     name = None
     arguments = None
     gql_type = None
     for child in tree.children:
         if child.type == 'description':
             description = child.value
         elif child.type == 'IDENT':
             name = String(str(child.value), ast_node=child)
         elif child.type == 'type':
             gql_type = child.value
         elif child.type == 'arguments':
             arguments = child.value
         elif child.type == 'discard':
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLField(
         name=name,
         gql_type=gql_type,
         arguments=arguments,
         description=description
     )
 def scalar_type_definition(self, tree: Tree) -> GraphQLScalarType:
     description = None
     name = None
     directives = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "IDENT":
             name = child.value
         elif child.type == "directives":
             directives = child.value
         elif child.type == "discard" or child.type == "SCALAR":
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     scalar = GraphQLScalarType(
         name=name,
         description=description,
         schema=self._schema,
         directives=directives,
     )
     self._schema.add_custom_scalar_definition(scalar)
     return scalar
Esempio n. 14
0
 def object_value(self, tree: Tree) -> SchemaNode:
     obj = {}
     for child in tree.children:
         if child.type == "object_field":
             obj[child.value[0]] = child.value[
                 1]  # name, value = child.value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return SchemaNode("object_value", obj)
 def object_value(self, tree: Tree) -> SchemaNode:
     obj = {}
     for child in tree.children:
         if child.type == 'object_field':
             name, value = child.value
             obj[name] = value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return SchemaNode('object_value', obj)
Esempio n. 16
0
 def directive(self, tree: Tree) -> SchemaNode:
     name = None
     arguments = None
     for child in tree.children:
         if child.type == "IDENT":
             name = child.value
         elif child.type == "arguments":
             arguments = child.value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return SchemaNode("directive", (name, arguments))
 def argument(self, tree: Tree) -> SchemaNode:
     name = None
     value = None
     for child in tree.children:
         if child.type == 'IDENT':
             name = String(str(child.value), ast_node=child)
         elif child.type == 'value':
             value = child.value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return SchemaNode('argument', (name, value))
Esempio n. 18
0
 def argument(self, tree: Tree) -> SchemaNode:
     name = None
     value = None
     for child in tree.children:
         if child.type == "IDENT":
             name = child.value
         elif child.type == "value":
             value = child.value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return SchemaNode("argument", (name, value))
 def enum_value_definition(self, tree: Tree) -> GraphQLEnumValue:
     description = None
     directives = None
     value = None
     for child in tree.children:
         if child.type == "description":
             description = child.value
         elif child.type == "enum_value":
             value = child.value
         elif child.type == "discard":
             pass
         elif child.type == "directives":
             directives = child.value
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     return GraphQLEnumValue(value, description, directives=directives)
 def enum_value_definition(self, tree: Tree) -> GraphQLEnumValue:
     # TODO: Add directives
     description = None
     value: GraphQLEnumValue = None
     for child in tree.children:
         if child.type == 'description':
             description = child.value
         elif child.type == 'enum_value':
             value = child.value
         elif child.type == 'discard':
             pass
         else:
             raise UnexpectedASTNode(
                 "Unexpected AST node `{}`, type `{}`".format(
                     child, child.__class__.__name__))
     if description:
         value.description = description
     return value