Skip to content

Commit

Permalink
Add description to schema parser and printer
Browse files Browse the repository at this point in the history
Descriptions are now part of the [graphql spec](https://facebook.github.io/graphql/June2018/#sec-Descriptions).
This commit brings graphql-core inline with the spec.
  • Loading branch information
phil303 committed Dec 9, 2018
1 parent a40730a commit 0af0dbc
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 56 deletions.
48 changes: 34 additions & 14 deletions graphql/language/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,14 @@ def __hash__(self):


class StringValue(Value):
__slots__ = ("loc", "value")
__slots__ = ("loc", "value", "is_block_string")
_fields = ("value",)

def __init__(self, value, loc=None):
def __init__(self, value, loc=None, is_block_string=False):
# type: (str, Optional[Loc]) -> None
self.loc = loc
self.value = value
self.is_block_string = is_block_string

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -989,7 +990,7 @@ def __hash__(self):


class ObjectTypeDefinition(TypeDefinition):
__slots__ = ("loc", "name", "interfaces", "directives", "fields")
__slots__ = ("loc", "name", "interfaces", "directives", "fields", "description")
_fields = ("name", "interfaces", "fields")

def __init__(
Expand All @@ -999,19 +1000,20 @@ def __init__(
interfaces=None, # type: Optional[List[NamedType]]
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.interfaces = interfaces
self.fields = fields
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
return self is other or (
isinstance(other, ObjectTypeDefinition)
and
isinstance(other, ObjectTypeDefinition) and
# self.loc == other.loc and
self.name == other.name
and self.interfaces == other.interfaces
Expand Down Expand Up @@ -1042,7 +1044,7 @@ def __hash__(self):


class FieldDefinition(Node):
__slots__ = ("loc", "name", "arguments", "type", "directives")
__slots__ = ("loc", "name", "arguments", "type", "directives", "description")
_fields = ("name", "arguments", "type")

def __init__(
Expand All @@ -1052,13 +1054,15 @@ def __init__(
type, # type: Union[NamedType, NonNullType, ListType]
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.arguments = arguments
self.type = type
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1094,7 +1098,7 @@ def __hash__(self):


class InputValueDefinition(Node):
__slots__ = ("loc", "name", "type", "default_value", "directives")
__slots__ = ("loc", "name", "type", "default_value", "directives", "description")
_fields = ("name", "type", "default_value")

def __init__(
Expand All @@ -1104,13 +1108,15 @@ def __init__(
default_value=None, # type: Any
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.type = type
self.default_value = default_value
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1147,7 +1153,7 @@ def __hash__(self):


class InterfaceTypeDefinition(TypeDefinition):
__slots__ = ("loc", "name", "fields", "directives")
__slots__ = ("loc", "name", "fields", "directives", "description")
_fields = ("name", "fields")

def __init__(
Expand All @@ -1156,12 +1162,14 @@ def __init__(
fields, # type: List[FieldDefinition]
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.fields = fields
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1194,7 +1202,7 @@ def __hash__(self):


class UnionTypeDefinition(TypeDefinition):
__slots__ = ("loc", "name", "types", "directives")
__slots__ = ("loc", "name", "types", "directives", "description")
_fields = ("name", "types")

def __init__(
Expand All @@ -1203,12 +1211,14 @@ def __init__(
types, # type: List[NamedType]
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.types = types
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1241,19 +1251,21 @@ def __hash__(self):


class ScalarTypeDefinition(TypeDefinition):
__slots__ = ("loc", "name", "directives")
__slots__ = ("loc", "name", "directives", "description")
_fields = ("name",)

def __init__(
self,
name, # type: Name
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1284,7 +1296,7 @@ def __hash__(self):


class EnumTypeDefinition(TypeDefinition):
__slots__ = ("loc", "name", "values", "directives")
__slots__ = ("loc", "name", "values", "directives", "description")
_fields = ("name", "values")

def __init__(
Expand All @@ -1293,12 +1305,14 @@ def __init__(
values, # type: List[EnumValueDefinition]
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.values = values
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1331,19 +1345,21 @@ def __hash__(self):


class EnumValueDefinition(Node):
__slots__ = ("loc", "name", "directives")
__slots__ = ("loc", "name", "directives", "description")
_fields = ("name",)

def __init__(
self,
name, # type: Name
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1374,7 +1390,7 @@ def __hash__(self):


class InputObjectTypeDefinition(TypeDefinition):
__slots__ = ("loc", "name", "fields", "directives")
__slots__ = ("loc", "name", "fields", "directives", "description")
_fields = ("name", "fields")

def __init__(
Expand All @@ -1383,12 +1399,14 @@ def __init__(
fields, # type: List[InputValueDefinition]
loc=None, # type: Optional[Loc]
directives=None, # type: Optional[List[Directive]]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.loc = loc
self.name = name
self.fields = fields
self.directives = directives
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -1454,7 +1472,7 @@ def __hash__(self):


class DirectiveDefinition(TypeSystemDefinition):
__slots__ = ("loc", "name", "arguments", "locations")
__slots__ = ("loc", "name", "arguments", "locations", "description")
_fields = ("name", "locations")

def __init__(
Expand All @@ -1463,12 +1481,14 @@ def __init__(
locations, # type: List[Name]
arguments=None, # type: Optional[List[InputValueDefinition]]
loc=None, # type: Optional[Loc]
description=None, # type: Optional[String]
):
# type: (...) -> None
self.name = name
self.locations = locations
self.loc = loc
self.arguments = arguments
self.description = description

def __eq__(self, other):
# type: (Any) -> bool
Expand Down
Loading

0 comments on commit 0af0dbc

Please sign in to comment.