|
87 | 87 | # Note: The fields onOperation, onFragment and onField are deprecated |
88 | 88 | "name": GraphQLField( |
89 | 89 | GraphQLNonNull(GraphQLString), |
90 | | - resolve=lambda directive, _info: directive.name, |
| 90 | + resolve=DirectiveResolvers.name, |
91 | 91 | ), |
92 | 92 | "description": GraphQLField( |
93 | | - GraphQLString, resolve=lambda directive, _info: directive.description |
| 93 | + GraphQLString, |
| 94 | + resolve=DirectiveResolvers.description, |
94 | 95 | ), |
95 | 96 | "isRepeatable": GraphQLField( |
96 | 97 | GraphQLNonNull(GraphQLBoolean), |
97 | | - resolve=lambda directive, _info: directive.is_repeatable, |
| 98 | + resolve=DirectiveResolvers.is_repeatable, |
98 | 99 | ), |
99 | 100 | "locations": GraphQLField( |
100 | 101 | GraphQLNonNull(GraphQLList(GraphQLNonNull(__DirectiveLocation))), |
101 | | - resolve=lambda directive, _info: directive.locations, |
| 102 | + resolve=DirectiveResolvers.locations, |
102 | 103 | ), |
103 | 104 | "args": GraphQLField( |
104 | 105 | GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))), |
105 | | - resolve=lambda directive, _info: directive.args.items(), |
| 106 | + args={ |
| 107 | + "includeDeprecated": GraphQLArgument( |
| 108 | + GraphQLBoolean, default_value=False |
| 109 | + ) |
| 110 | + }, |
| 111 | + resolve=DirectiveResolvers.args, |
106 | 112 | ), |
107 | 113 | }, |
108 | 114 | ) |
109 | 115 |
|
110 | 116 |
|
| 117 | +class DirectiveResolvers: |
| 118 | + @staticmethod |
| 119 | + def name(directive, _info): |
| 120 | + return directive.name |
| 121 | + |
| 122 | + @staticmethod |
| 123 | + def description(directive, _info): |
| 124 | + return directive.description |
| 125 | + |
| 126 | + @staticmethod |
| 127 | + def is_repeatable(directive, _info): |
| 128 | + return directive.is_repeatable |
| 129 | + |
| 130 | + @staticmethod |
| 131 | + def locations(directive, _info): |
| 132 | + return directive.locations |
| 133 | + |
| 134 | + # noinspection PyPep8Naming |
| 135 | + @staticmethod |
| 136 | + def args(directive, _info, includeDeprecated=False): |
| 137 | + items = directive.args.items() |
| 138 | + return ( |
| 139 | + list(items) |
| 140 | + if includeDeprecated |
| 141 | + else [item for item in items if item[1].deprecation_reason is None] |
| 142 | + ) |
| 143 | + |
| 144 | + |
111 | 145 | __DirectiveLocation: GraphQLEnumType = GraphQLEnumType( |
112 | 146 | name="__DirectiveLocation", |
113 | 147 | description="A Directive can be adjacent to many parts of the GraphQL" |
|
206 | 240 | " types possible at runtime. List and NonNull types compose" |
207 | 241 | " other types.", |
208 | 242 | fields=lambda: { |
209 | | - "kind": GraphQLField( |
210 | | - GraphQLNonNull(__TypeKind), resolve=TypeFieldResolvers.kind |
211 | | - ), |
212 | | - "name": GraphQLField(GraphQLString, resolve=TypeFieldResolvers.name), |
213 | | - "description": GraphQLField( |
214 | | - GraphQLString, resolve=TypeFieldResolvers.description |
215 | | - ), |
| 243 | + "kind": GraphQLField(GraphQLNonNull(__TypeKind), resolve=TypeResolvers.kind), |
| 244 | + "name": GraphQLField(GraphQLString, resolve=TypeResolvers.name), |
| 245 | + "description": GraphQLField(GraphQLString, resolve=TypeResolvers.description), |
216 | 246 | "specifiedByURL": GraphQLField( |
217 | | - GraphQLString, resolve=TypeFieldResolvers.specified_by_url |
| 247 | + GraphQLString, resolve=TypeResolvers.specified_by_url |
218 | 248 | ), |
219 | 249 | "fields": GraphQLField( |
220 | 250 | GraphQLList(GraphQLNonNull(__Field)), |
|
223 | 253 | GraphQLBoolean, default_value=False |
224 | 254 | ) |
225 | 255 | }, |
226 | | - resolve=TypeFieldResolvers.fields, |
| 256 | + resolve=TypeResolvers.fields, |
227 | 257 | ), |
228 | 258 | "interfaces": GraphQLField( |
229 | | - GraphQLList(GraphQLNonNull(__Type)), resolve=TypeFieldResolvers.interfaces |
| 259 | + GraphQLList(GraphQLNonNull(__Type)), resolve=TypeResolvers.interfaces |
230 | 260 | ), |
231 | 261 | "possibleTypes": GraphQLField( |
232 | 262 | GraphQLList(GraphQLNonNull(__Type)), |
233 | | - resolve=TypeFieldResolvers.possible_types, |
| 263 | + resolve=TypeResolvers.possible_types, |
234 | 264 | ), |
235 | 265 | "enumValues": GraphQLField( |
236 | 266 | GraphQLList(GraphQLNonNull(__EnumValue)), |
|
239 | 269 | GraphQLBoolean, default_value=False |
240 | 270 | ) |
241 | 271 | }, |
242 | | - resolve=TypeFieldResolvers.enum_values, |
| 272 | + resolve=TypeResolvers.enum_values, |
243 | 273 | ), |
244 | 274 | "inputFields": GraphQLField( |
245 | 275 | GraphQLList(GraphQLNonNull(__InputValue)), |
|
248 | 278 | GraphQLBoolean, default_value=False |
249 | 279 | ) |
250 | 280 | }, |
251 | | - resolve=TypeFieldResolvers.input_fields, |
| 281 | + resolve=TypeResolvers.input_fields, |
252 | 282 | ), |
253 | | - "ofType": GraphQLField(__Type, resolve=TypeFieldResolvers.of_type), |
| 283 | + "ofType": GraphQLField(__Type, resolve=TypeResolvers.of_type), |
254 | 284 | }, |
255 | 285 | ) |
256 | 286 |
|
257 | 287 |
|
258 | | -class TypeFieldResolvers: |
| 288 | +class TypeResolvers: |
259 | 289 | @staticmethod |
260 | 290 | def kind(type_, _info): |
261 | 291 | if is_scalar_type(type_): |
|
0 commit comments