Skip to content

Commit e95e1a9

Browse files
committed
Implement core type validation tests, part 1.
1 parent a649405 commit e95e1a9

File tree

8 files changed

+427
-24
lines changed

8 files changed

+427
-24
lines changed

graphql/core/type/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def define_field_map(type, field_map):
237237
for arg_name, arg in field_args.items():
238238
assert_valid_name(arg_name)
239239
assert isinstance(arg, GraphQLArgument), (
240-
'{}.{}({}:) argument must be an instance of GraphQLArgument'.format(type, field_name, arg_name)
240+
'{}.{}({}:) argument must be an instance of GraphQLArgument.'.format(type, field_name, arg_name)
241241
)
242242
assert is_input_type(arg.type), (
243243
'{}.{}({}:) argument type must be Input Type but got: {}.'.format(type, field_name, arg_name,

tests/core_starwars/__init__.py

Whitespace-only changes.

tests/core_starwars/starwars_fixtures.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,40 @@
55
luke = Human(
66
id='1000',
77
name='Luke Skywalker',
8-
friends=[ '1002', '1003', '2000', '2001' ],
9-
appearsIn=[ 4, 5, 6 ],
8+
friends=['1002', '1003', '2000', '2001'],
9+
appearsIn=[4, 5, 6],
1010
homePlanet='Tatooine',
1111
)
1212

1313
vader = Human(
1414
id='1001',
1515
name='Darth Vader',
16-
friends=[ '1004' ],
17-
appearsIn=[ 4, 5, 6 ],
16+
friends=['1004'],
17+
appearsIn=[4, 5, 6],
1818
homePlanet='Tatooine',
1919
)
2020

2121
han = Human(
2222
id='1002',
2323
name='Han Solo',
24-
friends=[ '1000', '1003', '2001' ],
25-
appearsIn=[ 4, 5, 6 ],
24+
friends=['1000', '1003', '2001'],
25+
appearsIn=[4, 5, 6],
2626
homePlanet=None,
2727
)
2828

2929
leia = Human(
3030
id='1003',
3131
name='Leia Organa',
32-
friends=[ '1000', '1002', '2000', '2001' ],
33-
appearsIn=[ 4, 5, 6 ],
32+
friends=['1000', '1002', '2000', '2001'],
33+
appearsIn=[4, 5, 6],
3434
homePlanet='Alderaan',
3535
)
3636

3737
tarkin = Human(
3838
id='1004',
3939
name='Wilhuff Tarkin',
40-
friends=[ '1001' ],
41-
appearsIn=[ 4 ],
40+
friends=['1001'],
41+
appearsIn=[4],
4242
homePlanet=None,
4343
)
4444

@@ -55,16 +55,16 @@
5555
threepio = Droid(
5656
id='2000',
5757
name='C-3PO',
58-
friends=[ '1000', '1002', '1003', '2001' ],
59-
appearsIn=[ 4, 5, 6 ],
58+
friends=['1000', '1002', '1003', '2001'],
59+
appearsIn=[4, 5, 6],
6060
primaryFunction='Protocol',
6161
)
6262

6363
artoo = Droid(
6464
id='2001',
6565
name='R2-D2',
66-
friends=[ '1000', '1002', '1003' ],
67-
appearsIn=[ 4, 5, 6 ],
66+
friends=['1000', '1002', '1003'],
67+
appearsIn=[4, 5, 6],
6868
primaryFunction='Astromech',
6969
)
7070

@@ -73,6 +73,7 @@
7373
'2001': artoo,
7474
}
7575

76+
7677
def getCharacter(id):
7778
return humanData.get(id) or droidData.get(id)
7879

tests/core_starwars/starwars_schema.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
GraphQLSchema,
1111
GraphQLString,
1212
)
13-
import starwars_fixtures
13+
from .starwars_fixtures import getHero, getHuman, getFriends, getDroid
1414

1515
episodeEnum = GraphQLEnumType(
1616
'Episode',
@@ -52,7 +52,7 @@
5252
description='Which movies they appear in.'
5353
),
5454
},
55-
resolve_type=lambda character, *_: humanType if starwars_fixtures.getHuman(character.id) else droidType,
55+
resolve_type=lambda character, *_: humanType if getHuman(character.id) else droidType,
5656
)
5757

5858
humanType = GraphQLObjectType(
@@ -70,7 +70,7 @@
7070
'friends': GraphQLField(
7171
GraphQLList(characterInterface),
7272
description='The friends of the human, or an empty list if they have none.',
73-
resolver=lambda human, *_: starwars_fixtures.getFriends(human),
73+
resolver=lambda human, *_: getFriends(human),
7474
),
7575
'appearsIn': GraphQLField(
7676
GraphQLList(episodeEnum),
@@ -99,7 +99,7 @@
9999
'friends': GraphQLField(
100100
GraphQLList(characterInterface),
101101
description='The friends of the droid, or an empty list if they have none.',
102-
resolver=lambda droid, *_: starwars_fixtures.getFriends(droid),
102+
resolver=lambda droid, *_: getFriends(droid),
103103
),
104104
'appearsIn': GraphQLField(
105105
GraphQLList(episodeEnum),
@@ -125,7 +125,7 @@
125125
type=episodeEnum,
126126
)
127127
},
128-
resolver=lambda root, args, *_: starwars_fixtures.getHero(args.get('episode')),
128+
resolver=lambda root, args, *_: getHero(args.get('episode')),
129129
),
130130
'human': GraphQLField(
131131
humanType,
@@ -135,7 +135,7 @@
135135
type=GraphQLNonNull(GraphQLString),
136136
)
137137
},
138-
resolver=lambda root, args, *_: starwars_fixtures.getHuman(args['id']),
138+
resolver=lambda root, args, *_: getHuman(args['id']),
139139
),
140140
'droid': GraphQLField(
141141
droidType,
@@ -145,7 +145,7 @@
145145
type=GraphQLNonNull(GraphQLString),
146146
)
147147
},
148-
resolver=lambda root, args, *_: starwars_fixtures.getDroid(args['id']),
148+
resolver=lambda root, args, *_: getDroid(args['id']),
149149
),
150150
}
151151
)

tests/core_starwars/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from starwars_schema import StarWarsSchema
1+
from .starwars_schema import StarWarsSchema
22
from graphql.core import graphql
33
from graphql.core.error import format_error
44

tests/core_starwars/test_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from graphql.core.language.source import Source
22
from graphql.core.language.parser import parse
33
from graphql.core.validation import validate
4-
from starwars_schema import StarWarsSchema
4+
from .starwars_schema import StarWarsSchema
55

66

77
def validation_errors(query):

tests/core_type/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)