Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
AWhetter committed Aug 5, 2023
1 parent da4bb5a commit 7fdcfd4
Show file tree
Hide file tree
Showing 30 changed files with 114 additions and 43 deletions.
34 changes: 17 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
graphql2sphinx
autogqlschema
==============

.. image:: https://readthedocs.org/projects/graphql2sphinx/badge/?version=latest
:target: https://graphql2sphinx.readthedocs.org
.. image:: https://readthedocs.org/projects/autogqlschema/badge/?version=latest
:target: https://autogqlschema.readthedocs.org
:alt: Documentation

.. image:: https://github.com/AWhetter/graphql2sphinx/actions/workflows/main.yml/badge.svg?branch=main
:target: https://github.com/AWhetter/graphql2sphinx/actions/workflows/main.yml?query=branch%3Amain
.. image:: https://github.com/AWhetter/autogqlschema/actions/workflows/main.yml/badge.svg?branch=main
:target: https://github.com/AWhetter/autogqlschema/actions/workflows/main.yml?query=branch%3Amain
:alt: Github Build Status

.. image:: https://img.shields.io/pypi/v/graphql2sphinx.svg
:target: https://pypi.org/project/graphql2sphinx/
.. image:: https://img.shields.io/pypi/v/autogqlschema.svg
:target: https://pypi.org/project/autogqlschema/
:alt: PyPI Version

.. image:: https://img.shields.io/pypi/pyversions/graphql2sphinx.svg
:target: https://pypi.org/project/graphql2sphinx/
.. image:: https://img.shields.io/pypi/pyversions/autogqlschema.svg
:target: https://pypi.org/project/autogqlschema/
:alt: Supported Python Versions

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
Expand All @@ -27,7 +27,7 @@ A Sphinx extension for automatically documenting GraphQL schemas.
Getting Started
---------------

The following steps will walk through how to add ``graphql2sphinx`` to an existing Sphinx project.
The following steps will walk through how to add ``autogqlschema`` to an existing Sphinx project.
For instructions on how to set up a Sphinx project,
see Sphinx's documentation on
`Getting Started <https://www.sphinx-doc.org/en/master/usage/quickstart.html>`_.
Expand All @@ -36,25 +36,25 @@ see Sphinx's documentation on
Installation
~~~~~~~~~~~~

``graphql2sphinx`` can be installed through pip:
``autogqlschema`` can be installed through pip:

.. code-block:: bash
pip install graphql2sphinx
pip install autogqlschema
Next, add ``graphql2sphinx`` to the ``extensions`` list in your Sphinx project's `conf.py`.
Next, add ``autogqlschema`` to the ``extensions`` list in your Sphinx project's `conf.py`.

.. code-block:: python
extensions.append("graphql2sphinx")
extensions.append("autogqlschema")
Usage
-----

Each directive accepts a small snippet of the original schema.
For more detailed usage, see the documentation:
https://graphql2sphinx.readthedocs.io/en/latest/
https://autogqlschema.readthedocs.io/en/latest/

TODO

Expand Down Expand Up @@ -87,13 +87,13 @@ You can also get black to format your changes for you:

.. code-block:: bash
black graphql2sphinx.py tests/
black autogqlschema.py tests/
Versioning
----------

We use `SemVer <https://semver.org/>`_ for versioning. For the versions available, see the `tags on this repository <https://github.com/AWhetter/graphql2sphinx/tags>`_.
We use `SemVer <https://semver.org/>`_ for versioning. For the versions available, see the `tags on this repository <https://github.com/AWhetter/autogqlschema/tags>`_.


License
Expand Down
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'graphql2sphinx'
project = 'autogqlschema'
copyright = '2023, Ashley Whetter'
author = 'Ashley Whetter'
release = '0.1.0'
Expand All @@ -15,7 +15,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'graphql2sphinx',
'autogqlschema',
'sphinx.ext.intersphinx',
]

Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "graphql2sphinx"
name = "autogqlschema"
authors = [
{name = "Ashley Whetter", email = "ashley@awhetter.co.uk"},
]
Expand Down Expand Up @@ -37,14 +37,14 @@ doc = [
]

[project.urls]
Source = "https://github.com/AWhetter/graphql2sphinx"
Documentation = "https://graphql2sphinx.readthedocs.org"
Source = "https://github.com/AWhetter/autogqlschema"
Documentation = "https://autogqlschema.readthedocs.org"

[tool.pylint]
disable = "R,unused-argument"

[tool.towncrier]
directory = "doc/changes"
filename = "CHANGELOG.rst"
package = "graphql2sphinx"
title_format = "graphql2sphinx v{version} ({project_date})"
package = "autogqlschema"
title_format = "autogqlschema v{version} ({project_date})"
12 changes: 6 additions & 6 deletions src/graphql2sphinx/__init__.py → src/autogqlschema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


def builder_inited(app):
template_dir = app.config.graphql2sphinx_template_dir
template_dir = app.config.autogqlschema_template_dir
if template_dir and not os.path.isabs(template_dir):
template_dir = os.path.join(app.srcdir, app.config.graphql2sphinx_template_dir)
template_dir = os.path.join(app.srcdir, app.config.autogqlschema_template_dir)

sphinx_mapper_obj = Mapper(app, template_dir=template_dir, url_root=url_root)

Expand All @@ -32,12 +32,12 @@ def builder_inited(app):


def build_finished(app, exception):
if not app.config.graphql2sphinx_keep_files:
if not app.config.autogqlschema_keep_files:
normalised_root = os.path.normpath(
os.path.join(app.srcdir, app.config.autoapi_root)
)
if app.verbosity > 1:
LOGGER.info(bold("[graphql2sphinx] ") + darkgreen("Cleaning generated .rst files"))
LOGGER.info(bold("[autogqlschema] ") + darkgreen("Cleaning generated .rst files"))
shutil.rmtree(normalised_root)


Expand All @@ -50,9 +50,9 @@ def setup(app):
app.add_config_value("autoapi_member_order", "bysource", "html")
app.add_config_value("autoapi_file_patterns", None, "html")
app.add_config_value("autoapi_dirs", [], "html")
app.add_config_value("graphql2sphinx_keep_files", False, "html")
app.add_config_value("autogqlschema_keep_files", False, "html")
app.add_config_value("autoapi_add_toctree_entry", True, "html")
app.add_config_value("graphql2sphinx_template_dir", None, "html")
app.add_config_value("autogqlschema_template_dir", None, "html")
app.add_config_value("autoapi_include_summaries", None, "html")
app.add_config_value("autoapi_python_use_implicit_namespaces", False, "html")
app.add_config_value("autoapi_python_class_content", "class", "html")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def load(self, patterns, dirs, ignore=None):
"""
paths = list(self.find_files(patterns=patterns, dirs=dirs, ignore=ignore))
for path in sphinx.util.status_iterator(
paths, bold("[graphql2sphinx] Reading files... "), "darkgreen", len(paths)
paths, bold("[autogqlschema] Reading files... "), "darkgreen", len(paths)
):
data = self.read_file(path=path)
if data:
Expand All @@ -36,7 +36,7 @@ def map(self, options=None):
"""Trigger find of serialized sources and build objects"""
for _, data in sphinx.util.status_iterator(
self.paths.items(),
bold("[graphql2sphinx] ") + "Mapping Data... ",
bold("[autogqlschema] ") + "Mapping Data... ",
length=len(self.paths),
stringify_func=(lambda x: x[0]),
):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import operator
from typing import Optional, Sequence, Type, TypeVar

import graphql
import graphql.type
from graphql.language import ast as gql_ast
import graphql.utilities

from ._objects import (
GraphQLDirective,
Expand Down Expand Up @@ -410,6 +412,10 @@ def _parse_uniontype(self, node: graphql.type.GraphQLUnionType) -> GraphQLUnion:
def parse(self, node: graphql.type.GraphQLSchema) -> GraphQLSchema:
return self._parse_schema(node)

def parse_from_source(self, source: str) -> GraphQLSchema:
def parse_from_source(self, source: str, *sources: str) -> GraphQLSchema:
schema = graphql.utilities.build_schema(source)
for extension in sources:
document = graphql.parse(extension)
schema = graphql.utilities.extend_schema(schema, document)

return self.parse(schema)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from graphql2sphinx import _objects
from autogqlschema import _objects

def _explain(left, right):
result = []
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"graphql2sphinx",
"autogqlschema",
]

templates_path = ["_templates"]
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/directives.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ directive @directive2 on FIELD_DEFINITION | ARGUMENT_DEFINITION
directive3 tests that arguments are parsed
"""
directive @directive3(
"name1 tests that arguments can be documented."
name1: input1
"arg1 tests that arguments can be documented."
arg1: input1
) on SCALAR

4 changes: 2 additions & 2 deletions tests/fixtures/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Directives
directive2 tests parsing with multiple type system directive locations

.. gql:directive:: @directive3(name1: type1) on SCALAR
.. gql:directive:: @directive3(arg1: type1) on SCALAR
directive3 tests that arguments are parsed

:argument name1: name1 tests that arguments can be documented.
:argument arg1: arg1 tests that arguments can be documented.
1 change: 1 addition & 0 deletions tests/fixtures/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
inputs
interfaces
scalars
schemas
type_objects
unions
5 changes: 4 additions & 1 deletion tests/fixtures/interfaces.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ interface interface2 @directiveA {
"interface2.field1 tests that directives are parsed"
field1: Int @directiveA
"interface2.field2 tests that arguments are parsed"
field2(arg1: Int = 0): String
field2(
"arg1 tests that arguments can be documented"
arg1: Int = 0
): String
}
2 changes: 2 additions & 0 deletions tests/fixtures/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Directives
interface2.field2 tests that arguments are parsed
:argument arg1: arg1 tests that arguments can be documented
Roles
-----
Expand Down
54 changes: 54 additions & 0 deletions tests/fixtures/schemas.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Schemas
=======

Directives
----------

.. gql:type:: MyQueryRootType1
.. gql:type:: MyMutationRootType1
.. gql:type:: MySubscriptionRootType1
.. gql:schema:: schema1
schema1 tests parsing the simplest possible schema definition

.. gql:schema:: schema2
:definition: @directive1 @directive2

schema2 tests that directives are parsed, and operation types are rendered
and linked.
Note that these types are defined outside of the schema,
because users may choose to document a schema without nesting all objects
under the schema directive.

:optype MyQueryRootType1 query:
:optype MyMutationRootType1 mutation:
:optype MySubscriptionRootType1 subscription:

.. gql:schema:: schema3
schema3 tests that default operation names are used for operation types given without a name.

:optype query:
:optype mutation:
:optype subscription:

.. gql:schema:: schema4
schema4 tests that schema directives act as a part to child objects.
Also that Operation Types link with or without specifying the schema name.

:optype MyQueryRootType2 query:
:optype schema4.MyMutationRootType2 mutation:

.. gql:type:: MyQueryRootType2
.. gql:type:: MyMutationRootType2
Roles
-----

:gql:schema:`schema1`
5 changes: 4 additions & 1 deletion tests/fixtures/type_objects.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ type type2 @directiveA {
"type2.field1 tests that directives are parsed"
field1: Int @directiveA
"type2.field2 tests that arguments are parsed"
field2(arg1: Int = 0): String
field2(
"arg1 tests that arguments can be documented"
arg1: Int = 0
): String
}
2 changes: 2 additions & 0 deletions tests/fixtures/type_objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Directives
type2.field2 tests that arguments are parsed
:argument arg1: arg1 tests that arguments can be documented
Roles
-----
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib

from graphql2sphinx import _objects
from graphql2sphinx._parser import Parser
from autogqlschema import _objects
from autogqlschema._parser import Parser


def parse(path):
Expand Down

0 comments on commit 7fdcfd4

Please sign in to comment.