def test_extends_objects_by_adding_implemented_interfaces():
    ast = parse('''
      extend type Foo {
        newObject: NewObject
        newInterface: NewInterface
        newUnion: NewUnion
        newScalar: NewScalar
        newEnum: NewEnum
        newTree: [Foo]!
      }
      type NewObject implements NewInterface {
        baz: String
      }
      type NewOtherObject {
        fizz: Int
      }
      interface NewInterface {
        baz: String
      }
      union NewUnion = NewObject | NewOtherObject
      scalar NewScalar
      enum NewEnum {
        OPTION_A
        OPTION_B
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    assert print_schema(extended_schema) == \
        '''type Bar implements SomeInterface {
def test_extends_without_altering_original_schema():
    ast = parse('''
      extend type Query {
        newField: String
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    assert 'newField' in print_schema(extended_schema)
    assert 'newField' not in print_schema(test_schema)
def test_extends_objects_by_adding_implemented_interfaces():
    ast = parse('''
      extend type Biz implements SomeInterface {
        name: String
        some: SomeInterface
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    assert print_schema(extended_schema) == \
        '''type Bar implements SomeInterface {
def test_extends_objects_by_adding_new_fields():
    ast = parse('''
      extend type Foo {
        newField: String
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    # print original_print
    assert print_schema(extended_schema) == \
        '''type Bar implements SomeInterface {
def test_extends_objects_by_adding_implemented_new_interfaces():
    ast = parse('''
      extend type Foo implements NewInterface {
        baz: String
      }
      interface NewInterface {
        baz: String
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    assert print_schema(extended_schema) == \
        '''type Bar implements SomeInterface {
def test_extends_objects_by_adding_new_fields_with_arguments():
    ast = parse('''
      extend type Foo {
        newField(arg1: String, arg2: NewInputObj!): String
      }
      input NewInputObj {
        field1: Int
        field2: [Float]
        field3: String!
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    assert print_schema(extended_schema) == \
        '''type Bar implements SomeInterface {
def test_may_extend_mutations_and_subscriptions():
    mutationSchema = GraphQLSchema(
        query=GraphQLObjectType(
            'Query',
            fields=lambda: {
                'queryField': GraphQLField(GraphQLString),
            }
        ),
        mutation=GraphQLObjectType(
            'Mutation',
            fields={
                'mutationField': GraphQLField(GraphQLString),
            }
        ),
        subscription=GraphQLObjectType(
            'Subscription',
            fields={
                'subscriptionField': GraphQLField(GraphQLString),
            }
        ),
    )

    ast = parse('''
      extend type Query {
        newQueryField: Int
      }
      extend type Mutation {
        newMutationField: Int
      }
      extend type Subscription {
        newSubscriptionField: Int
      }
    ''')
    original_print = print_schema(mutationSchema)
    extended_schema = extend_schema(mutationSchema, ast)
    assert extend_schema != mutationSchema
    assert print_schema(mutationSchema) == original_print
    assert print_schema(extended_schema) == \
        '''type Mutation {
def test_extends_objects_multiple_times():
    ast = parse('''
      extend type Biz implements NewInterface {
        buzz: String
      }
      extend type Biz implements SomeInterface {
        name: String
        some: SomeInterface
        newFieldA: Int
      }
      extend type Biz {
        newFieldA: Int
        newFieldB: Float
      }
      interface NewInterface {
        buzz: String
      }
    ''')
    original_print = print_schema(test_schema)
    extended_schema = extend_schema(test_schema, ast)
    assert extend_schema != test_schema
    assert print_schema(test_schema) == original_print
    assert print_schema(extended_schema) == \
        '''type Bar implements SomeInterface {
def update_schema(schema):
    print('[~] Generating Schema Documents... ')
    executor = Executor(execution_middlewares=[SynchronousExecutionMiddleware()], map_type=OrderedDict)
    result = executor.execute(schema, introspection_query)
    if result.errors:
        print('[X] Error inspecting schema: ', result.errors)

    else:
        with open(os.path.join(os.path.dirname(__file__), '..', 'schema.json'), 'w') as fp:
            json.dump({'data': result.data}, fp, indent=2)

        print('[~] Wrote schema.json')

    with open(os.path.join(os.path.dirname(__file__), '..', 'schema.graphql'), 'w') as fp:
        fp.write(print_schema(schema))

    print('[~] Wrote schema.graphql')

    print('[!] Done.')
Esempio n. 10
0
 def __str__(self):
     return print_schema(self.schema)
def print_for_test(schema):
    return '\n' + print_schema(schema)
def cycle_output(body, query_type, mutation_type=None, subscription_type=None):
    ast = parse(body)
    schema = build_ast_schema(ast, query_type, mutation_type, subscription_type)
    return '\n' + print_schema(schema)
def print_for_test(schema):
    return '\n' + print_schema(schema)
Esempio n. 14
0
 def __str__(self):
     return print_schema(self.schema)