Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Commit

Permalink
introspection descriptions for scalars and introspection
Browse files Browse the repository at this point in the history
Commit:
0530394f9ac81e235070b67d9dd0a95b54b3c754 [0530394]
Parents:
662e316f04
Author:
Lee Byron <[email protected]>
Date:
18 September 2015 at 5:09:26 AM

-----

Fix tests

Commit:
8c52207af26bf9818479681811e881d747ef17c4 [8c52207]
Parents:
0530394f9a
Author:
Lee Byron <[email protected]>
Date:
18 September 2015 at 9:37:18 AM SGT
  • Loading branch information
sogko committed Mar 14, 2016
1 parent ba491dd commit 723a432
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
27 changes: 26 additions & 1 deletion introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion introspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 23 additions & 7 deletions scalars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down Expand Up @@ -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{} {
Expand All @@ -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{} {
Expand Down Expand Up @@ -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:
Expand All @@ -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{} {
Expand Down

0 comments on commit 723a432

Please sign in to comment.