Skip to content

Instantly share code, notes, and snippets.

@syrusakbary
Last active October 9, 2015 18:06
Show Gist options
  • Save syrusakbary/d116212d3a1f688519c2 to your computer and use it in GitHub Desktop.
Save syrusakbary/d116212d3a1f688519c2 to your computer and use it in GitHub Desktop.
ObjectType Fields order
from graphql.core import graphql
from graphql.core.type import (
GraphQLObjectType,
GraphQLField,
GraphQLString,
GraphQLSchema,
GraphQLNonNull,
)
humanType = GraphQLObjectType(
'Human',
description='A humanoid creature in the Star Wars universe.',
fields=lambda: {
'id': GraphQLField(
GraphQLNonNull(GraphQLString),
resolver=lambda human, *_: 'random id',
),
'name': GraphQLField(
GraphQLString,
resolver=lambda human, *_: 'random name',
),
},
)
StarWarsSchema = GraphQLSchema(query=humanType)
query1 = '''
query HeroNameQuery {
name
id
}
'''
result1 = graphql(StarWarsSchema, query1)
query2 = '''
query HeroNameQuery {
id
name
}
'''
result2 = graphql(StarWarsSchema, query2)
order1 = json.dumps(result1.data)
order2 = json.dumps(result2.data)
print order1, order2
assert order1 != order2
# Result.data should be {'name': 'random name', 'id': 'random id'}
# Instead of {'id': 'random id', 'name': 'random name'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment