11from collections import namedtuple
22from typing import Union
33
4- from pytest import raises
4+ from pytest import mark , raises
55
66from graphql import graphql_sync
77from graphql .language import parse , print_ast , DocumentNode , InterfaceTypeDefinitionNode
3434)
3535from graphql .utilities import build_ast_schema , build_schema , print_schema , print_type
3636
37+ from ..fixtures import big_schema_sdl # noqa: F401
3738from ..utils import dedent
3839
3940
@@ -42,7 +43,7 @@ def cycle_sdl(sdl: str) -> str:
4243
4344 This function does a full cycle of going from a string with the contents of the SDL,
4445 parsed in a schema AST, materializing that schema AST into an in-memory
45- GraphQLSchema, and then finally printing that GraphQL into the SDÖ .
46+ GraphQLSchema, and then finally printing that GraphQL into the SDL .
4647 """
4748 ast = parse (sdl )
4849 schema = build_ast_schema (ast )
@@ -1184,3 +1185,27 @@ def rejects_invalid_ast():
11841185 with raises (TypeError ) as exc_info :
11851186 build_ast_schema ({}) # type: ignore
11861187 assert str (exc_info .value ) == "Must provide valid Document AST."
1188+
1189+ # This currently does not work because of how extend_schema is implemented
1190+ @mark .skip (reason = "pickling of schemas is not yet supported" )
1191+ def can_pickle_and_unpickle_big_schema (big_schema_sdl ): # noqa: F811
1192+ import pickle
1193+
1194+ # create a schema from the kitchen sink SDL
1195+ schema = build_schema (big_schema_sdl , assume_valid_sdl = True )
1196+ # check that the schema can be pickled
1197+ # (particularly, there should be no recursion error,
1198+ # or errors because of trying to pickle lambdas or local functions)
1199+ dumped = pickle .dumps (schema )
1200+ # check that the pickle size is reasonable
1201+ assert len (dumped ) < 50 * len (big_schema_sdl )
1202+ loaded = pickle .loads (dumped )
1203+
1204+ # check that the un-pickled schema is still the same
1205+ assert loaded == schema
1206+ # check that pickling again creates the same result
1207+ dumped_again = pickle .dumps (schema )
1208+ assert dumped_again == dumped
1209+
1210+ # check that printing the unpickled schema gives the same SDL
1211+ assert cycle_sdl (print_schema (schema )) == cycle_sdl (big_schema_sdl )
0 commit comments