| 
 | 1 | +from ...language.base import parse  | 
 | 2 | +from ...utils.ast_to_code import ast_to_code  | 
 | 3 | +from ..compiled import GraphQLCompiledDocument  | 
 | 4 | +from .schema import schema  | 
 | 5 | + | 
 | 6 | + | 
 | 7 | +def test_compileddocument_from_module_dict():  | 
 | 8 | + document_string = '{ hello }'  | 
 | 9 | + document_ast = parse(document_string)  | 
 | 10 | + document = GraphQLCompiledDocument.from_module_dict(schema, {  | 
 | 11 | + 'document_string': document_string,  | 
 | 12 | + 'document_ast': document_ast,  | 
 | 13 | + 'execute': lambda *_: True  | 
 | 14 | + })  | 
 | 15 | + assert document.operations_map == {  | 
 | 16 | + None: 'query'  | 
 | 17 | + }  | 
 | 18 | + assert document.document_string == document_string  | 
 | 19 | + assert document.document_ast == document_ast  | 
 | 20 | + assert document.schema == schema  | 
 | 21 | + assert document.execute()  | 
 | 22 | + | 
 | 23 | + | 
 | 24 | +def test_compileddocument_from_code():  | 
 | 25 | + document_string = '{ hello }'  | 
 | 26 | + document_ast = parse(document_string)  | 
 | 27 | + code = '''  | 
 | 28 | +# -*- coding: utf-8 -*-  | 
 | 29 | +from __future__ import unicode_literals  | 
 | 30 | +
  | 
 | 31 | +from graphql.language import ast  | 
 | 32 | +from graphql.language.parser import Loc  | 
 | 33 | +from graphql.language.source import Source  | 
 | 34 | +
  | 
 | 35 | +
  | 
 | 36 | +schema = None  | 
 | 37 | +document_string = """{document_string}"""  | 
 | 38 | +source = Source(document_string)  | 
 | 39 | +
  | 
 | 40 | +
  | 
 | 41 | +def loc(start, end):  | 
 | 42 | + return Loc(start, end, source)  | 
 | 43 | +
  | 
 | 44 | +document_ast = {document_ast}  | 
 | 45 | +
  | 
 | 46 | +def execute(*_):  | 
 | 47 | + return True  | 
 | 48 | +'''.format(document_string=document_string, document_ast=ast_to_code(document_ast))  | 
 | 49 | + document = GraphQLCompiledDocument.from_code(schema, code)  | 
 | 50 | + assert document.operations_map == {  | 
 | 51 | + None: 'query'  | 
 | 52 | + }  | 
 | 53 | + assert document.document_string == document_string  | 
 | 54 | + assert document.document_ast == document_ast  | 
 | 55 | + assert document.schema == schema  | 
 | 56 | + assert document.execute()  | 
0 commit comments