From 723a432f414ed00968af31c73906efb3d61f2dd1 Mon Sep 17 00:00:00 2001 From: Hafiz Ismail Date: Mon, 14 Mar 2016 08:16:20 +0800 Subject: [PATCH] introspection descriptions for scalars and introspection Commit: 0530394f9ac81e235070b67d9dd0a95b54b3c754 [0530394] Parents: 662e316f04 Author: Lee Byron Date: 18 September 2015 at 5:09:26 AM ----- Fix tests Commit: 8c52207af26bf9818479681811e881d747ef17c4 [8c52207] Parents: 0530394f9a Author: Lee Byron Date: 18 September 2015 at 9:37:18 AM SGT --- introspection.go | 27 ++++++++++++++++++++++++++- introspection_test.go | 2 +- scalars.go | 30 +++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/introspection.go b/introspection.go index f1defd0e..d6ab0c04 100644 --- a/introspection.go +++ b/introspection.go @@ -36,7 +36,7 @@ func init() { __TypeKind = NewEnum(EnumConfig{ Name: "__TypeKind", - Description: "An enum describing what kind of type a given __Type is", + Description: "An enum describing what kind of type a given `__Type` is", Values: EnumValueConfigMap{ "SCALAR": &EnumValueConfig{ Value: TypeKindScalar, @@ -83,6 +83,15 @@ func init() { // Note: some fields (for e.g "fields", "interfaces") are defined later due to cyclic reference __Type = NewObject(ObjectConfig{ Name: "__Type", + Description: "The fundamental unit of any GraphQL Schema is the type. There are " + + "many kinds of types in GraphQL as represented by the `__TypeKind` enum." + + "\n\nDepending on the kind of a type, certain fields describe " + + "information about that type. Scalar types provide no information " + + "beyond a name and description, while Enum types provide their values. " + + "Object and Interface types provide the fields they describe. Abstract " + + "types, Union and Interface, provide the Object types possible " + + "at runtime. List and NonNull types compose other types.", + Fields: Fields{ "kind": &Field{ Type: NewNonNull(__TypeKind), @@ -125,6 +134,9 @@ func init() { __InputValue = NewObject(ObjectConfig{ Name: "__InputValue", + Description: "Arguments provided to Fields or Directives and the input fields of an " + + "InputObject are represented as Input Values which describe their type " + + "and optionally a default value.", Fields: Fields{ "name": &Field{ Type: NewNonNull(String), @@ -137,6 +149,8 @@ func init() { }, "defaultValue": &Field{ Type: String, + Description: "A GraphQL-formatted string representing the default value for this " + + "input value.", Resolve: func(p ResolveParams) (interface{}, error) { if inputVal, ok := p.Source.(*Argument); ok { if inputVal.DefaultValue == nil { @@ -160,6 +174,8 @@ func init() { __Field = NewObject(ObjectConfig{ Name: "__Field", + Description: "Object and Interface types are described by a list of Fields, each of " + + "which has a name, potentially a list of arguments, and a return type.", Fields: Fields{ "name": &Field{ Type: NewNonNull(String), @@ -196,6 +212,12 @@ func init() { __Directive = NewObject(ObjectConfig{ Name: "__Directive", + Description: "A Directives provides a way to describe alternate runtime execution and " + + "type validation behavior in a GraphQL document. " + + "\n\nIn some cases, you need to provide options to alter GraphQL's " + + "execution behavior in ways field arguments will not suffice, such as " + + "conditionally including or skipping a field. Directives provide this by " + + "describing additional information to the executor.", Fields: Fields{ "name": &Field{ Type: NewNonNull(String), @@ -295,6 +317,9 @@ func init() { __EnumValue = NewObject(ObjectConfig{ Name: "__EnumValue", + Description: "One possible value for a given Enum. Enum values are unique values, not " + + "a placeholder for a string or numeric value. However an Enum value is " + + "returned in a JSON response as a string.", Fields: Fields{ "name": &Field{ Type: NewNonNull(String), diff --git a/introspection_test.go b/introspection_test.go index 4fe94437..6425b9db 100644 --- a/introspection_test.go +++ b/introspection_test.go @@ -1344,7 +1344,7 @@ func TestIntrospection_ExposesDescriptionsOnEnums(t *testing.T) { Data: map[string]interface{}{ "typeKindType": map[string]interface{}{ "name": "__TypeKind", - "description": `An enum describing what kind of type a given __Type is`, + "description": "An enum describing what kind of type a given `__Type` is", "enumValues": []interface{}{ map[string]interface{}{ "name": "SCALAR", diff --git a/scalars.go b/scalars.go index 14782369..c752b852 100644 --- a/scalars.go +++ b/scalars.go @@ -69,7 +69,11 @@ func coerceInt(value interface{}) interface{} { // Int is the GraphQL Integer type definition. var Int *Scalar = NewScalar(ScalarConfig{ - Name: "Int", + Name: "Int", + Description: "The `Int` scalar type represents non-fractional signed whole numeric " + + "values. Int can represent values between -(2^53 - 1) and 2^53 - 1 since " + + "represented in JSON as double-precision floating point numbers specified" + + "by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).", Serialize: coerceInt, ParseValue: coerceInt, ParseLiteral: func(valueAST ast.Value) interface{} { @@ -108,7 +112,10 @@ func coerceFloat32(value interface{}) interface{} { // Float is the GraphQL float type definition. var Float *Scalar = NewScalar(ScalarConfig{ - Name: "Float", + Name: "Float", + Description: "The `Float` scalar type represents signed double-precision fractional " + + "values as specified by " + + "[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). ", Serialize: coerceFloat32, ParseValue: coerceFloat32, ParseLiteral: func(valueAST ast.Value) interface{} { @@ -132,7 +139,10 @@ func coerceString(value interface{}) interface{} { // String is the GraphQL string type definition var String *Scalar = NewScalar(ScalarConfig{ - Name: "String", + Name: "String", + Description: "The `String` scalar type represents textual data, represented as UTF-8 " + + "character sequences. The String type is most often used by GraphQL to " + + "represent free-form human-readable text.", Serialize: coerceString, ParseValue: coerceString, ParseLiteral: func(valueAST ast.Value) interface{} { @@ -175,9 +185,10 @@ func coerceBool(value interface{}) interface{} { // Boolean is the GraphQL boolean type definition var Boolean *Scalar = NewScalar(ScalarConfig{ - Name: "Boolean", - Serialize: coerceBool, - ParseValue: coerceBool, + Name: "Boolean", + Description: "The `Boolean` scalar type represents `true` or `false`.", + Serialize: coerceBool, + ParseValue: coerceBool, ParseLiteral: func(valueAST ast.Value) interface{} { switch valueAST := valueAST.(type) { case *ast.BooleanValue: @@ -189,7 +200,12 @@ var Boolean *Scalar = NewScalar(ScalarConfig{ // ID is the GraphQL id type definition var ID *Scalar = NewScalar(ScalarConfig{ - Name: "ID", + Name: "ID", + Description: "The `ID` scalar type represents a unique identifier, often used to " + + "refetch an object or as key for a cache. The ID type appears in a JSON " + + "response as a String; however, it is not intended to be human-readable. " + + "When expected as an input type, any string (such as `\"4\"`) or integer " + + "(such as `4`) input value will be accepted as an ID.", Serialize: coerceString, ParseValue: coerceString, ParseLiteral: func(valueAST ast.Value) interface{} {