Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from preply/extend-fix
Browse files Browse the repository at this point in the history
fix external/requires regex mismatch
  • Loading branch information
erebus1 committed Jan 9, 2020
2 parents 85d59eb + 2afdac7 commit 22941f1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion graphene_federation/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _mark_field(
# todo write tests on regexp
schema_field_name = to_camel_case(field_name) if auto_camelcase else field_name
pattern = re.compile(
r"(\s%s\s[^\{]*\{[^\}]*\s%s[\s]*:[\s]*[^\s]+)(\s)" % (
r"(type\s%s\s[^\{]*\{[^\}]*\s%s[\s]*:[\s]*[^\s]+)(\s)" % (
entity_name, schema_field_name))
schema = pattern.sub(
rf'\g<1> {decorator_resolver(getattr(field, mark_attr_name))} ', schema)
Expand Down
14 changes: 14 additions & 0 deletions integration_tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ services:
timeout: 10s
retries: 10

service_d:
build: service_d/.
volumes:
- ./service_d/src:/project/src
- ../:/project/federation_deps
command: sh -c "pip install ./federation_deps && python ./src/app.py"
healthcheck:
test: ["CMD", "curl", "-XGET", "http://0.0.0.0:5000/graphql"]
interval: 1s
timeout: 10s
retries: 10

federation:
build: federation/.
volumes:
Expand All @@ -54,6 +66,8 @@ services:
condition: service_healthy
service_c:
condition: service_healthy
service_d:
condition: service_healthy

proxy_dep:
image: busybox
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/federation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {ApolloGateway} from '@apollo/gateway'
const serviceA_url: string = 'http://service_a:5000/graphql';
const serviceB_url: string = 'http://service_b:5000/graphql';
const serviceC_url: string = 'http://service_c:5000/graphql';
const serviceD_url: string = 'http://service_d:5000/graphql';

const gateway = new ApolloGateway({
serviceList: [
{ name: 'service_a', url: serviceA_url },
{ name: 'service_b', url: serviceB_url },
{ name: 'service_c', url: serviceC_url },
{ name: 'service_d', url: serviceD_url },
],
});

Expand Down
6 changes: 5 additions & 1 deletion integration_tests/service_c/src/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from graphene import ObjectType, String, Int, List, NonNull, Field
from graphene_federation import build_schema, extend, external, requires
from graphene_federation import build_schema, extend, external, requires, key


@extend(fields='id')
Expand All @@ -12,11 +12,15 @@ def resolve_uppercase_email(self, info):
return self.primary_email.upper() if self.primary_email else self.primary_email


@key(fields='id')
class Article(ObjectType):
id = Int(required=True)
text = String(required=True)
author = Field(lambda: User)

def __resolve_reference(self, info, **kwargs):
return Article(id=self.id, text=f'text_{self.id}')


class Query(ObjectType):
articles = List(NonNull(lambda: Article))
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/service_d/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.6-alpine3.9

WORKDIR project
RUN apk add curl

COPY ./requirements.txt ./
RUN pip install -r requirements.txt

EXPOSE 5000
CMD [ "python", "./src/app.py"]
3 changes: 3 additions & 0 deletions integration_tests/service_d/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
graphene==2.1.7
flask==1.1.1
flask_graphql==2.0.0
Empty file.
12 changes: 12 additions & 0 deletions integration_tests/service_d/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask

from flask_graphql import GraphQLView
from schema import schema

app = Flask(__name__)
app.debug = True

app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))

if __name__ == '__main__':
app.run(host='0.0.0.0')
29 changes: 29 additions & 0 deletions integration_tests/service_d/src/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from graphene import ObjectType, Int, Field
from graphene_federation import build_schema, extend, external

"""
Alphabet order - matters
Y should be just after X in sdl
https://github.com/preply/graphene-federation/issues/26#issuecomment-572127271
"""


@extend(fields='id')
class Article(ObjectType):
id = external(Int(required=True))


class X(ObjectType):
x_article = Field(Article)


class Y(ObjectType):
id = Int(required=True)


class Query(ObjectType):
x = Field(X)
y = Field(Y)


schema = build_schema(query=Query)

0 comments on commit 22941f1

Please sign in to comment.