Skip to content

Commit

Permalink
Create subset of a schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp authored Apr 19, 2024
1 parent d6c3968 commit 5390e78
Show file tree
Hide file tree
Showing 8 changed files with 2,271 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.4.0 (UNRELEASED)

- Fixed handling of nested variables in objects and lists.
- Added `queries`, `mutations` and `subscriptions` APIs to `ProxySchema.add_remote_schema`, `ProxySchema.add_schema` and `copy_schema` for creating schemas that are subsets of other, larger schemas.


## 0.3.0 (2024-03-26)
Expand Down
24 changes: 24 additions & 0 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,30 @@ app = GraphQL(
)
```

## Creating a schema that is a subset of other schema

Following APIs support creating a new schema that is a subset of another schema:

- `ProxySchema.add_remote_schema`
- `ProxySchema.add_schema`
- `copy_schema`

To create a subset of other schema, specify which fields for `queries` and (optionally) `mutations` should be available in final schema:

```python
from ariadne_graphql_proxy import ProxySchema

proxy_schema = ProxySchema()
proxy_schema.add_remote_schema(
"https://example.com/e-commerce/",
queries=["categories", "products"],
)
```

All other `Query` fields and types that weren't used by those fields will be removed from the final schema, making it much smaller. If `mutations` option was not used, `Mutation` type will also be removed from the schema.

`queries` and `mutations` arguments can be combined with `exclude_types`, `exclude_fields`, `exclude_args`, `exclude_directives` and `exclude_directives_args`.


## imgix query params resolver

Expand Down
2 changes: 2 additions & 0 deletions ariadne_graphql_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .remote_schema import get_remote_schema
from .resolvers import set_resolver, unset_resolver
from .selections import merge_selection_sets, merge_selections
from .unwrap_type import unwrap_graphql_type

__all__ = [
"ForeignKeyResolver",
Expand Down Expand Up @@ -95,4 +96,5 @@
"set_resolver",
"setup_root_resolver",
"unset_resolver",
"unwrap_graphql_type",
]
Loading

0 comments on commit 5390e78

Please sign in to comment.