11import asyncio
2+ import warnings
23from typing import Any , AsyncGenerator , Dict , Generator , Optional , Union
34
45from graphql import (
2122class Client :
2223 def __init__ (
2324 self ,
24- schema : Optional [GraphQLSchema ] = None ,
25+ schema : Optional [Union [ str , GraphQLSchema ] ] = None ,
2526 introspection = None ,
2627 type_def : Optional [str ] = None ,
2728 transport : Optional [Union [Transport , AsyncTransport ]] = None ,
@@ -30,23 +31,34 @@ def __init__(
3031 ):
3132 assert not (
3233 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 :
3537 assert (
3638 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+
3846 if introspection :
3947 assert (
4048 not schema
4149 ), "Cannot provide introspection and schema at the same time."
4250 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 :
4457 assert (
4558 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 :
5062 transport = LocalSchemaTransport (schema )
5163
5264 # GraphQL schema
0 commit comments