Skip to content

Commit

Permalink
Handle graphql+response code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirusblk authored and patrick91 committed Apr 3, 2024
1 parent f8f5f13 commit 8846de2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/docs/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dataclasses
import inspect
import json
import re
import typing
from pathlib import Path
Expand Down Expand Up @@ -110,6 +111,7 @@ def find_examples(
[
*find_examples("docs/index.md"),
*find_examples("docs/general/"),
*find_examples("docs/guides/field-extensions.md"),
],
ids=str,
)
Expand Down Expand Up @@ -144,6 +146,8 @@ def test_docs(example: CodeExample, eval_example: EvalExample):

# Expected schema is likely to be a subset of the overall schema
assert expected_schema in actual_schema
elif example.prefix == "graphql+response":
check_gql_and_response(example)


def split_code_example(source_code: str) -> typing.Tuple[str, typing.Optional[str]]:
Expand Down Expand Up @@ -182,3 +186,16 @@ def construct_schema():
subscription=DOC_GLOBALS.get("Subscription"),
types=types,
)


def check_gql_and_response(example: CodeExample):
gql_query, expected_response_str = split_code_example(example.source)
expected_response = json.loads(expected_response_str)
schema = construct_schema()

result = schema.execute_sync(
query=gql_query,
)

assert result.errors is None
assert result.data == expected_response

0 comments on commit 8846de2

Please sign in to comment.