Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base implementation of interface #37

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions ariadne_graphql_modules/next/interfacetype.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from dataclasses import dataclass
from enum import Enum
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Type,
Union,
cast,
Sequence,
)

from ariadne import InterfaceType
Expand Down Expand Up @@ -39,13 +33,11 @@
)

from ..utils import parse_definition
from .base import GraphQLMetadata, GraphQLModel, GraphQLType
from .base import GraphQLMetadata, GraphQLModel
from .description import get_description_node


class GraphQLInterface(GraphQLObject):
__types__: Sequence[Type[GraphQLType]]
__implements__: Optional[Iterable[Union[Type[GraphQLType], Type[Enum]]]]
__valid_type__ = InterfaceTypeDefinitionNode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets repeat __abstract__: bool = True for posterity sake.


@classmethod
Expand Down
5 changes: 3 additions & 2 deletions ariadne_graphql_modules/next/objecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GraphQLObject(GraphQLType):
__description__: Optional[str]
__aliases__: Optional[Dict[str, str]]
__requires__: Optional[Iterable[Union[Type[GraphQLType], Type[Enum]]]]
__implements__: Optional[Iterable[Union[Type[GraphQLType], Type[Enum]]]]
__implements__: Optional[Iterable[Type[GraphQLType]]]

def __init__(self, **kwargs: Any):
for kwarg in kwargs:
Expand Down Expand Up @@ -236,6 +236,7 @@ def __get_graphql_types_with_schema__(
) -> Iterable["GraphQLType"]:
types: List[GraphQLType] = [cls]
types.extend(getattr(cls, "__requires__", []))
types.extend(getattr(cls, "__implements__", []))
return types

@classmethod
Expand Down Expand Up @@ -607,7 +608,7 @@ def get_field_args_from_resolver(


def get_field_args_out_names(
field_args: Dict[str, GraphQLObjectFieldArg]
field_args: Dict[str, GraphQLObjectFieldArg],
) -> Dict[str, str]:
out_names: Dict[str, str] = {}
for field_arg in field_args.values():
Expand Down
12 changes: 6 additions & 6 deletions tests_next/test_interface_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def search(*_) -> List[UserType | CommentType]:
CommentType(id=2, content="Hello World!"),
]

schema = make_executable_schema(QueryType, UserInterface, UserType)
schema = make_executable_schema(QueryType, UserType)

assert_schema_equals(
schema,
Expand All @@ -119,17 +119,17 @@ def search(*_) -> List[UserType | CommentType]:
summary: String!
score: Int!
}

interface UserInterface {
summary: String!
score: Int!
}

type Comment {
id: ID!
content: String!
}

interface UserInterface {
summary: String!
score: Int!
}

""",
)

Expand Down
Loading