diff --git a/doc/changes/+c23554ff.bugfix b/doc/changes/+c23554ff.bugfix new file mode 100644 index 0000000..bbdf709 --- /dev/null +++ b/doc/changes/+c23554ff.bugfix @@ -0,0 +1 @@ +Fix indentation issues causing incorrect rendering \ No newline at end of file diff --git a/src/autogqlschema/_templates/directive.rst.jinja b/src/autogqlschema/_templates/directive.rst.jinja index 8140d78..f3310b4 100644 --- a/src/autogqlschema/_templates/directive.rst.jinja +++ b/src/autogqlschema/_templates/directive.rst.jinja @@ -1,9 +1,9 @@ .. gql:directive:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for arg, arg_description in args.items() %} - :argument {{ arg }}: {% if arg_description %}{{ arg_description }}{% endif +%} + :argument {{ arg }}: {% if arg_description %}{{ arg_description|indent(6) }}{% endif +%} {% endfor %} diff --git a/src/autogqlschema/_templates/enum.rst.jinja b/src/autogqlschema/_templates/enum.rst.jinja index 985df43..de32572 100644 --- a/src/autogqlschema/_templates/enum.rst.jinja +++ b/src/autogqlschema/_templates/enum.rst.jinja @@ -1,7 +1,7 @@ .. gql:enum:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for child in children %} diff --git a/src/autogqlschema/_templates/enum_value.rst.jinja b/src/autogqlschema/_templates/enum_value.rst.jinja index 44b1876..04e509c 100644 --- a/src/autogqlschema/_templates/enum_value.rst.jinja +++ b/src/autogqlschema/_templates/enum_value.rst.jinja @@ -1,7 +1,6 @@ .. gql:enum:value:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} - \ No newline at end of file diff --git a/src/autogqlschema/_templates/input.rst.jinja b/src/autogqlschema/_templates/input.rst.jinja index b954cda..a28dd2e 100644 --- a/src/autogqlschema/_templates/input.rst.jinja +++ b/src/autogqlschema/_templates/input.rst.jinja @@ -1,7 +1,7 @@ .. gql:input:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for child in children %} diff --git a/src/autogqlschema/_templates/input_field.rst.jinja b/src/autogqlschema/_templates/input_field.rst.jinja index 0af3cc4..424ec7a 100644 --- a/src/autogqlschema/_templates/input_field.rst.jinja +++ b/src/autogqlschema/_templates/input_field.rst.jinja @@ -1,7 +1,6 @@ .. gql:input:field:: {{ signature }} {% if description %} - {{ description }} - + {{ description|indent(3) }} + {% endif %} - \ No newline at end of file diff --git a/src/autogqlschema/_templates/interface.rst.jinja b/src/autogqlschema/_templates/interface.rst.jinja index 3273e1c..3f697ff 100644 --- a/src/autogqlschema/_templates/interface.rst.jinja +++ b/src/autogqlschema/_templates/interface.rst.jinja @@ -1,7 +1,7 @@ .. gql:interface:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for child in children %} diff --git a/src/autogqlschema/_templates/interface_field.rst.jinja b/src/autogqlschema/_templates/interface_field.rst.jinja index e51eab4..349ea22 100644 --- a/src/autogqlschema/_templates/interface_field.rst.jinja +++ b/src/autogqlschema/_templates/interface_field.rst.jinja @@ -1,9 +1,9 @@ .. gql:interface:field:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for arg, arg_description in args.items() %} - :argument {{ arg }}: {% if arg_description %}{{ arg_description }}{% endif +%} + :argument {{ arg }}: {% if arg_description %}{{ arg_description|indent(6) }}{% endif +%} {% endfor %} diff --git a/src/autogqlschema/_templates/scalar.rst.jinja b/src/autogqlschema/_templates/scalar.rst.jinja index 3266f83..3341b32 100644 --- a/src/autogqlschema/_templates/scalar.rst.jinja +++ b/src/autogqlschema/_templates/scalar.rst.jinja @@ -1,7 +1,6 @@ .. gql:scalar:: {{ signature }} {% if description %} - {{ description }} - + {{ description|indent(3) }} + {% endif %} - \ No newline at end of file diff --git a/src/autogqlschema/_templates/schema.rst.jinja b/src/autogqlschema/_templates/schema.rst.jinja index b9fffe7..99d8c1d 100644 --- a/src/autogqlschema/_templates/schema.rst.jinja +++ b/src/autogqlschema/_templates/schema.rst.jinja @@ -2,7 +2,7 @@ :name: {{ name }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% if query_type %} @@ -14,7 +14,7 @@ {% if subscription_type %} :optype {{ subscription_type }} subscription: {% endif %} - + {% for child in children %} {{ renderer.render(child)|indent(3) }} {% endfor %} diff --git a/src/autogqlschema/_templates/type.rst.jinja b/src/autogqlschema/_templates/type.rst.jinja index 59843e4..6afabe9 100644 --- a/src/autogqlschema/_templates/type.rst.jinja +++ b/src/autogqlschema/_templates/type.rst.jinja @@ -1,7 +1,7 @@ .. gql:type:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for child in children %} diff --git a/src/autogqlschema/_templates/type_field.rst.jinja b/src/autogqlschema/_templates/type_field.rst.jinja index 21728b0..104ba52 100644 --- a/src/autogqlschema/_templates/type_field.rst.jinja +++ b/src/autogqlschema/_templates/type_field.rst.jinja @@ -1,10 +1,9 @@ .. gql:type:field:: {{ signature }} {% if description %} - {{ description }} + {{ description|indent(3) }} {% endif %} {% for arg, arg_description in args.items() %} - :argument {{ arg }}: {% if arg_description %}{{ arg_description }}{% endif +%} + :argument {{ arg }}: {% if arg_description %}{{ arg_description|indent(6) }}{% endif +%} {% endfor %} - \ No newline at end of file diff --git a/src/autogqlschema/_templates/union.rst.jinja b/src/autogqlschema/_templates/union.rst.jinja index 53023d0..cac3b88 100644 --- a/src/autogqlschema/_templates/union.rst.jinja +++ b/src/autogqlschema/_templates/union.rst.jinja @@ -1,7 +1,6 @@ .. gql:union:: {{ signature }} {% if description %} - {{ description }} - + {{ description|indent(3) }} + {% endif %} - \ No newline at end of file diff --git a/tests/fixtures/arguments.graphql b/tests/fixtures/arguments.graphql index 0c2c48d..2395921 100644 --- a/tests/fixtures/arguments.graphql +++ b/tests/fixtures/arguments.graphql @@ -24,7 +24,11 @@ type TestArgumentType { fieldA1( "arg1 tests that arguments can be documented" arg1: Int - "arg2 tests that arguments can be documented" + """ + arg2 tests that arguments can be documented. + + It also tests that multiline docstrings are formatted correctly. + """ arg2: input1 ): String diff --git a/tests/fixtures/directives.graphql b/tests/fixtures/directives.graphql index 894c140..ea95445 100644 --- a/tests/fixtures/directives.graphql +++ b/tests/fixtures/directives.graphql @@ -14,10 +14,18 @@ directive2 tests parsing with multiple type system directive locations directive @directive2 on FIELD_DEFINITION | ARGUMENT_DEFINITION """ -directive3 tests that arguments are parsed +directive3 tests that arguments are parsed. + +It also tests that multiline docstrings are formatted correctly. """ directive @directive3( "arg1 tests that arguments can be documented." arg1: input1 + """ + arg2 tests that arguments can be documented. + + It also tests that multiline docstrings are formatted correctly. + """ + arg2: input1 ) on SCALAR diff --git a/tests/fixtures/enums.graphql b/tests/fixtures/enums.graphql index f24e0c3..9c442a1 100644 --- a/tests/fixtures/enums.graphql +++ b/tests/fixtures/enums.graphql @@ -9,10 +9,16 @@ enum enum1 { } """ -enum2 tests that directives are parsed +enum2 tests that directives are parsed. + +It also tests that multiline docstrings are formatted correctly. """ enum enum2 @directiveA { - "enum2.value1 tests that directives are parsed" + """ + enum2.value1 tests that directives are parsed. + + It also tests that multiline docstrings are formatted correctly. + """ value1 @directiveA } diff --git a/tests/fixtures/inputs.graphql b/tests/fixtures/inputs.graphql index e479c32..b5f66e4 100644 --- a/tests/fixtures/inputs.graphql +++ b/tests/fixtures/inputs.graphql @@ -9,10 +9,16 @@ input input1 { } """ -input2 tests that directives are parsed +input2 tests that directives are parsed. + +It also tests that multiline docstrings are formatted correctly. """ input input2 @directiveA { - "input2.field1 tests that directives are parsed" + """ + input2.field1 tests that directives are parsed. + + It also tests that multiline docstrings are formatted correctly. + """ field1: Int @directiveA "input2.field2 tests that default values are parsed" field2: String = "defaultvaluefield2" diff --git a/tests/fixtures/interfaces.graphql b/tests/fixtures/interfaces.graphql index 3289e39..402621a 100644 --- a/tests/fixtures/interfaces.graphql +++ b/tests/fixtures/interfaces.graphql @@ -6,9 +6,17 @@ interface interface1 { field1: String } -"interface2 tests that directives are parsed" +""" +interface2 tests that directives are parsed. + +It also tests that multiline docstrings are formatted correctly. +""" interface interface2 @directive1 { - "interface2.field1 tests that directives are parsed" + """ + interface2.field1 tests that directives are parsed. + + It also tests that multiline docstrings are formatted correctly. + """ field1: Int @directive1 "interface2.field2 tests that arguments are parsed" field2( diff --git a/tests/fixtures/scalars.graphql b/tests/fixtures/scalars.graphql index 9f4590d..1e910a0 100644 --- a/tests/fixtures/scalars.graphql +++ b/tests/fixtures/scalars.graphql @@ -3,5 +3,9 @@ directive @directive1 on SCALAR "scalar1 tests parsing the simplest possible scalar definition" scalar scalar1 -"scalar2 tests that directives are parsed" +""" +scalar2 tests that directives are parsed. + +It also tests that multiline docstrings are formatted correctly. +""" scalar scalar2 @directive1 diff --git a/tests/fixtures/schemas_directives.graphql b/tests/fixtures/schemas_directives.graphql index 0261fec..c1e4fab 100644 --- a/tests/fixtures/schemas_directives.graphql +++ b/tests/fixtures/schemas_directives.graphql @@ -13,7 +13,11 @@ type MySubscriptionRootType { field1: Int } -"schema1 tests that directives are parsed, and operation types are rendered and linked." +""" +schema1 tests that directives are parsed, and operation types are rendered and linked. + +It also tests that multiline docstrings are formatted correctly. +""" schema @directive1 @directive2 { query: MyQueryRootType mutation: MyMutationRootType diff --git a/tests/fixtures/type_objects.graphql b/tests/fixtures/type_objects.graphql index e96d3d0..5474f2b 100644 --- a/tests/fixtures/type_objects.graphql +++ b/tests/fixtures/type_objects.graphql @@ -7,14 +7,26 @@ type type1 { } -"type2 tests that directives are parsed" +""" +type2 tests that directives are parsed. + +It also tests that multiline docstrings are formatted correctly. +""" type type2 @directive1 { - "type2.field1 tests that directives are parsed" + """ + type2.field1 tests that directives are parsed. + + It also tests that multiline docstrings are formatted correctly. + """ field1: Int @directive1 "type2.field2 tests that arguments are parsed" field2( - "arg1 tests that arguments can be documented." + """ + arg1 tests that arguments can be documented. + + It also tests that multiline docstrings are formatted correctly. + """ arg1: Int = 0 ): String } \ No newline at end of file diff --git a/tests/fixtures/unions.graphql b/tests/fixtures/unions.graphql index 32e2a97..546c327 100644 --- a/tests/fixtures/unions.graphql +++ b/tests/fixtures/unions.graphql @@ -11,5 +11,9 @@ type type2 { "union1 tests parsing the simplest possible union definition" union union1 = type1 | type2 -"union2 tests that directives are parsed" +""" +union2 tests that directives are parsed. + +It also tests that multiline docstrings are formatted correctly. +""" union union2 @directive1 = type1 | type2 diff --git a/tests/test_integration.py b/tests/test_integration.py index 04ca8a8..7f47bc5 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -80,9 +80,17 @@ def test_argument_fields(self, soup: bs4.BeautifulSoup): sig = soup.find(id="schema1.TestArgumentType.fieldA1") links = sig.parent.find("ul").find_all("li") assert len(links) == 2 - enum_link, value_link = links - assert enum_link.get_text().startswith("arg1") - assert value_link.get_text().startswith("arg2") + int_link, input_link = links + assert int_link.get_text().startswith("arg1") + assert int_link.get_text().endswith( + "arg1 tests that arguments can be documented" + ) + assert not soup.find("blockquote") + assert input_link.get_text().startswith("arg2") + assert input_link.get_text().endswith( + "arg2 tests that arguments can be documented.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) def test_type_is_linked(self, soup: bs4.BeautifulSoup): sig = soup.find(id="schema1.TestArgumentType.fieldA1") @@ -183,7 +191,10 @@ def test_multi_location(self, soup: bs4.BeautifulSoup): def test_with_argument(self, soup: bs4.BeautifulSoup): sig = soup.find(id="schema1.directive3") - assert signature_text(sig) == "directive @directive3(arg1: input1) on SCALAR" + assert ( + signature_text(sig) + == "directive @directive3(arg1: input1, arg2: input1) on SCALAR" + ) def test_role(self, soup: bs4.BeautifulSoup): links = soup.find(id="roles").find_all("a", "reference") @@ -191,6 +202,29 @@ def test_role(self, soup: bs4.BeautifulSoup): link = links[0] assert link.get_text() == "schema1.directive1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.directive3") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "directive3 tests that arguments are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + + links = sig.parent.find("ul").find_all("li") + assert len(links) == 2 + arg1_link, arg2_link = links + assert arg1_link.get_text().startswith("arg1") + assert arg1_link.get_text().endswith( + "arg1 tests that arguments can be documented." + ) + assert arg2_link.get_text().startswith("arg2") + assert arg2_link.get_text().endswith( + "arg2 tests that arguments can be documented.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) + class TestEnums: @pytest.fixture(scope="class") @@ -228,6 +262,23 @@ def test_role(self, soup: bs4.BeautifulSoup): assert enum_link.get_text() == "schema1.enum1" assert value_link.get_text() == "schema1.enum1.value1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.enum2") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "enum2 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + + sig = soup.find(id="schema1.enum2.value1") + docstring = sig.parent.dd + assert docstring.get_text().endswith( + "enum2.value1 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) + class TestInputs: @pytest.fixture(scope="class") @@ -269,6 +320,23 @@ def test_role(self, soup: bs4.BeautifulSoup): assert input_link.get_text() == "schema1.input1" assert field_link.get_text() == "schema1.input1.field1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.input2") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "input2 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + + sig = soup.find(id="schema1.input2.field1") + docstring = sig.parent.dd + assert docstring.get_text().endswith( + "input2.field1 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) + class TestInterfaces: @pytest.fixture(scope="class") @@ -310,6 +378,23 @@ def test_role(self, soup: bs4.BeautifulSoup): assert input_link.get_text() == "schema1.interface1" assert field_link.get_text() == "schema1.interface1.field1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.interface2") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "interface2 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + + sig = soup.find(id="schema1.interface2.field1") + docstring = sig.parent.dd + assert docstring.get_text().endswith( + "interface2.field1 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) + class TestScalars: @pytest.fixture(scope="class") @@ -333,6 +418,16 @@ def test_role(self, soup: bs4.BeautifulSoup): link = links[0] assert link.get_text() == "schema1.scalar1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.scalar2") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "scalar2 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + class TestSchemas: @pytest.fixture(scope="class") @@ -374,6 +469,16 @@ def test_with_directive(self, soup: bs4.BeautifulSoup): sig = soup.find(id="schema1") assert signature_text(sig) == "schema @directive1 @directive2" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "schema1 tests that directives are parsed, and operation types are rendered and linked.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + class TestSchemasOptionalOptypes: @pytest.fixture(scope="class") @@ -432,6 +537,33 @@ def test_role(self, soup: bs4.BeautifulSoup): assert input_link.get_text() == "schema1.type1" assert field_link.get_text() == "schema1.type1.field1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.type2") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "type2 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + + sig = soup.find(id="schema1.type2.field1") + docstring = sig.parent.dd + assert docstring.get_text().endswith( + "type2.field1 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) + + sig = soup.find(id="schema1.type2.field2") + links = sig.parent.find("ul").find_all("li") + assert len(links) == 1 + arg1_link = links[0] + assert arg1_link.get_text().startswith("arg1") + assert arg1_link.get_text().endswith( + "arg1 tests that arguments can be documented.\n" + "It also tests that multiline docstrings are formatted correctly.\n" + ) + class TestUnions: @pytest.fixture(scope="class") @@ -461,6 +593,16 @@ def test_role(self, soup: bs4.BeautifulSoup): link = links[0] assert link.get_text() == "schema1.union1" + def test_docstrings(self, soup: bs4.BeautifulSoup): + assert not soup.find("blockquote") + + sig = soup.find(id="schema1.union2") + docstring = sig.parent.dd + assert docstring.get_text().startswith( + "union2 tests that directives are parsed.\n" + "It also tests that multiline docstrings are formatted correctly." + ) + class TestRootDir: @pytest.fixture(scope="class")