1
1
import asyncio
2
+ import warnings
2
3
from typing import Any , AsyncGenerator , Dict , Generator , Optional , Union
3
4
4
5
from graphql import (
21
22
class Client :
22
23
def __init__ (
23
24
self ,
24
- schema : Optional [GraphQLSchema ] = None ,
25
+ schema : Optional [Union [ str , GraphQLSchema ] ] = None ,
25
26
introspection = None ,
26
27
type_def : Optional [str ] = None ,
27
28
transport : Optional [Union [Transport , AsyncTransport ]] = None ,
@@ -30,23 +31,34 @@ def __init__(
30
31
):
31
32
assert not (
32
33
type_def and introspection
33
- ), "Cannot provide introspection type definition at the same time."
34
- if transport and fetch_schema_from_transport :
34
+ ), "Cannot provide introspection and type definition at the same time."
35
+
36
+ if type_def :
35
37
assert (
36
38
not schema
37
- ), "Cannot fetch the schema from transport if is already provided."
39
+ ), "Cannot provide type definition and schema at the same time."
40
+ warnings .warn (
41
+ "type_def is deprecated; use schema instead" ,
42
+ category = DeprecationWarning ,
43
+ )
44
+ schema = type_def
45
+
38
46
if introspection :
39
47
assert (
40
48
not schema
41
49
), "Cannot provide introspection and schema at the same time."
42
50
schema = build_client_schema (introspection )
43
- elif type_def :
51
+
52
+ if isinstance (schema , str ):
53
+ type_def_ast = parse (schema )
54
+ schema = build_ast_schema (type_def_ast )
55
+
56
+ if transport and fetch_schema_from_transport :
44
57
assert (
45
58
not schema
46
- ), "Cannot provide type definition and schema at the same time."
47
- type_def_ast = parse (type_def )
48
- schema = build_ast_schema (type_def_ast )
49
- elif schema and not transport :
59
+ ), "Cannot fetch the schema from transport if is already provided."
60
+
61
+ if schema and not transport :
50
62
transport = LocalSchemaTransport (schema )
51
63
52
64
# GraphQL schema
0 commit comments