def test_missing_query(): schema = """type Author { name: String }""" with pytest.raises(ValueError, match="Query type is not defined in the schema"): gql_st.query(schema)
def get_case_strategy( self, endpoint: Endpoint, hooks: Optional[HookDispatcher] = None, feedback: Optional[Feedback] = None) -> SearchStrategy: constructor = partial(GraphQLCase, endpoint=endpoint) schema = graphql.build_client_schema(self.raw_schema) return st.builds(constructor, body=gql_st.query(schema))
def get_case_strategy( self, operation: APIOperation, hooks: Optional[HookDispatcher] = None, data_generation_method: DataGenerationMethod = DataGenerationMethod.default(), ) -> SearchStrategy: constructor = partial(GraphQLCase, operation=operation) return st.builds(constructor, body=gql_st.query(self.client_schema, fields=[operation.verbose_name]))
def get_case_strategy( self, operation: APIOperation, hooks: Optional[HookDispatcher] = None, data_generation_method: DataGenerationMethod = DataGenerationMethod.default(), ) -> SearchStrategy: constructor = partial(GraphQLCase, operation=operation) schema = graphql.build_client_schema(self.raw_schema) return st.builds(constructor, body=gql_st.query(schema))
def test_custom_scalar(): # custom scalar types are not supported directly schema = """ scalar Date type Object { created: Date } type Query { getByDate(created: Date): Object } """ @given(query=gql_st.query(schema)) def test(query): pass with pytest.raises(TypeError, match="Custom scalar types are not supported"): test()
def test_arguments(arguments, node_names, notnull): if notnull: arguments += "!" query_type = f"""type Query {{ getModel({arguments}): Model }}""" @given(query=gql_st.query(SCHEMA + query_type)) def test(query): for node_name in node_names: assert node_name not in query if notnull: assert "getModel(" in query parsed = graphql.parse(query) selection = parsed.definitions[0].selection_set.selections[0] if notnull: # there should be one argument if it is not null assert len(selection.arguments) == 1 # at least one Model field is selected assert len(selection.selection_set.selections) > 0 test()
def assert_schema(schema): @given(query=gql_st.query(schema)) def test(query): graphql.parse(query) test()
def as_strategy(self) -> st.SearchStrategy[GraphQLCase]: constructor = partial(GraphQLCase, path=self.path) return st.builds(constructor, data=gql_st.query(self.schema))