Skip to content

Commit 39dd375

Browse files
author
Thomas Leonard
committed
feat!: make graphene-federation compatible to graphene v3
1 parent e3f14d7 commit 39dd375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+10410
-4459
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ jobs:
1717
python -m pip install --upgrade pip
1818
pip install -e ".[dev]"
1919
- name: Run lint 💅
20-
run: black graphene_federation --check
20+
run: |
21+
black graphene_federation --check
22+
mypy graphene_federation

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]
@@ -104,4 +106,4 @@ venv.bak/
104106
.mypy_cache/
105107

106108
.idea
107-
node_modules
109+
node_modules

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8-slim
1+
FROM python:3.10-alpine
22

33
# Disable Python buffering in order to see the logs immediatly
44
ENV PYTHONUNBUFFERED=1

Makefile

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,45 @@
22
# Integration testing
33
# -------------------------
44

5-
.PHONY: integration-build ## Build environment for integration tests
6-
integration-build:
5+
integration-build: ## Build environment for integration tests
76
cd integration_tests && docker-compose build
7+
.PHONY: integration-build
88

9-
.PHONY: integration-test ## Run integration tests
10-
integration-test:
9+
integration-tests: ## Run integration tests
1110
cd integration_tests && docker-compose down && docker-compose run --rm tests
11+
.PHONY: integration-test
1212

1313
# -------------------------
1414
# Development and unit testing
1515
# -------------------------
1616

17-
.PHONY: dev-setup ## Install development dependencies
18-
dev-setup:
17+
dev-setup: ## Install development dependencies
1918
docker-compose up -d && docker-compose exec graphene_federation bash
19+
.PHONY: dev-setup
2020

21-
.PHONY: tests ## Run unit tests
22-
tests:
21+
tests: ## Run unit tests
2322
docker-compose run graphene_federation py.test graphene_federation --cov=graphene_federation -vv
23+
.PHONY: tests
24+
25+
check-style: ## Run linting
26+
docker-compose run graphene_federation black graphene_federation --check
27+
.PHONY: check-style
28+
29+
check-types: ## Run typing check
30+
docker-compose run graphene_federation mypy graphene_federation
31+
.PHONY: check-types
32+
33+
# -------------------------
34+
# Help
35+
# -------------------------
36+
37+
help: ## Show help
38+
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
39+
.PHONY: help
40+
41+
.DEFAULT_GOAL := help
42+
43+
.EXPORT_ALL_VARIABLES:
44+
DOCKER_BUILDKIT = 1
45+
COMPOSE_DOCKER_CLI_BUILD = 1
46+

Pipfile

Lines changed: 0 additions & 20 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 218 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: '3.5'
33
services:
44

55
graphene_federation:
6+
container_name: graphene_federation
67
build:
78
context: .
89
volumes:

graphene_federation/entity.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
from typing import Any, Dict, Union
1+
from __future__ import annotations
22

3-
from graphene import List, Union, Schema
3+
from typing import Any, Callable
44

5-
import graphene
5+
from graphene import List, Union
6+
7+
from graphene.types.schema import Schema
8+
from graphene.types.schema import TypeMap
69

710
from .types import _Any
811
from .utils import field_name_to_type_attribute
912

1013

11-
def get_entities(schema: Schema) -> Dict[str, Any]:
14+
def get_entities(schema: Schema) -> dict[str, Any]:
1215
"""
13-
Find all the entities from the schema.
16+
Find all the entities from the type map.
1417
They can be easily distinguished from the other type as
1518
the `@key` and `@extend` decorators adds a `_sdl` attribute to them.
1619
"""
20+
type_map: TypeMap = schema.graphql_schema.type_map
1721
entities = {}
18-
for type_name, type_ in schema._type_map.items():
22+
for type_name, type_ in type_map.items():
1923
if not hasattr(type_, "graphene_type"):
2024
continue
2125
if getattr(type_.graphene_type, "_keys", None):
2226
entities[type_name] = type_.graphene_type
2327
return entities
2428

2529

26-
def get_entity_cls(entities: Dict[str, Any]):
30+
def get_entity_cls(entities: dict[str, Any]) -> Union:
2731
"""
2832
Create _Entity type which is a union of all the entities types.
2933
"""
@@ -46,14 +50,12 @@ def get_entity_query(schema: Schema):
4650
entity_type = get_entity_cls(entities_dict)
4751

4852
class EntityQuery:
49-
entities = graphene.List(
50-
entity_type, name="_entities", representations=List(_Any)
51-
)
53+
entities = List(entity_type, name="_entities", representations=List(_Any))
5254

5355
def resolve_entities(self, info, representations):
5456
entities = []
5557
for representation in representations:
56-
type_ = schema.get_type(representation["__typename"])
58+
type_ = schema.graphql_schema.get_type(representation["__typename"])
5759
model = type_.graphene_type
5860
model_arguments = representation.copy()
5961
model_arguments.pop("__typename")
@@ -76,7 +78,7 @@ def resolve_entities(self, info, representations):
7678
return EntityQuery
7779

7880

79-
def key(fields: str):
81+
def key(fields: str) -> Callable:
8082
"""
8183
Take as input a field that should be used as key for that entity.
8284
See specification: https://www.apollographql.com/docs/federation/federation-spec/#key

0 commit comments

Comments
 (0)