Skip to content

Commit 170c5b5

Browse files
authored
Merge pull request #192 from graphql-go/sogko/0.6.0
graphql-js v0.6.0
2 parents 669f84d + 12580b5 commit 170c5b5

27 files changed

+2166
-891
lines changed

definition.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ var _ Output = (*NonNull)(nil)
120120
// Composite interface for types that may describe the parent context of a selection set.
121121
type Composite interface {
122122
Name() string
123+
Description() string
124+
String() string
125+
Error() error
123126
}
124127

125128
var _ Composite = (*Object)(nil)

directives.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
package graphql
22

33
const (
4+
// Operations
45
DirectiveLocationQuery = "QUERY"
56
DirectiveLocationMutation = "MUTATION"
67
DirectiveLocationSubscription = "SUBSCRIPTION"
78
DirectiveLocationField = "FIELD"
89
DirectiveLocationFragmentDefinition = "FRAGMENT_DEFINITION"
910
DirectiveLocationFragmentSpread = "FRAGMENT_SPREAD"
1011
DirectiveLocationInlineFragment = "INLINE_FRAGMENT"
12+
13+
// Schema Definitions
14+
DirectiveLocationSchema = "SCHEMA"
15+
DirectiveLocationScalar = "SCALAR"
16+
DirectiveLocationObject = "OBJECT"
17+
DirectiveLocationFieldDefinition = "FIELD_DEFINITION"
18+
DirectiveLocationArgumentDefinition = "ARGUMENT_DEFINITION"
19+
DirectiveLocationInterface = "INTERFACE"
20+
DirectiveLocationUnion = "UNION"
21+
DirectiveLocationEnum = "ENUM"
22+
DirectiveLocationEnumValue = "ENUM_VALUE"
23+
DirectiveLocationInputObject = "INPUT_OBJECT"
24+
DirectiveLocationInputFieldDefinition = "INPUT_FIELD_DEFINITION"
1125
)
1226

27+
// DefaultDeprecationReason Constant string used for default reason for a deprecation.
28+
const DefaultDeprecationReason = "No longer supported"
29+
30+
// SpecifiedRules The full list of specified directives.
31+
var SpecifiedDirectives = []*Directive{
32+
IncludeDirective,
33+
SkipDirective,
34+
DeprecatedDirective,
35+
}
36+
1337
// Directive structs are used by the GraphQL runtime as a way of modifying execution
1438
// behavior. Type system creators will usually not create these directly.
1539
type Directive struct {
@@ -76,7 +100,7 @@ func NewDirective(config DirectiveConfig) *Directive {
76100
return dir
77101
}
78102

79-
// IncludeDirective is used to conditionally include fields or fragments
103+
// IncludeDirective is used to conditionally include fields or fragments.
80104
var IncludeDirective = NewDirective(DirectiveConfig{
81105
Name: "include",
82106
Description: "Directs the executor to include this field or fragment only when " +
@@ -94,7 +118,7 @@ var IncludeDirective = NewDirective(DirectiveConfig{
94118
},
95119
})
96120

97-
// SkipDirective Used to conditionally skip (exclude) fields or fragments
121+
// SkipDirective Used to conditionally skip (exclude) fields or fragments.
98122
var SkipDirective = NewDirective(DirectiveConfig{
99123
Name: "skip",
100124
Description: "Directs the executor to skip this field or fragment when the `if` " +
@@ -111,3 +135,22 @@ var SkipDirective = NewDirective(DirectiveConfig{
111135
DirectiveLocationInlineFragment,
112136
},
113137
})
138+
139+
// DeprecatedDirective Used to declare element of a GraphQL schema as deprecated.
140+
var DeprecatedDirective = NewDirective(DirectiveConfig{
141+
Name: "deprecated",
142+
Description: "Marks an element of a GraphQL schema as no longer supported.",
143+
Args: FieldConfigArgument{
144+
"reason": &ArgumentConfig{
145+
Type: String,
146+
Description: "Explains why this element was deprecated, usually also including a " +
147+
"suggestion for how to access supported similar data. Formatted" +
148+
"in [Markdown](https://daringfireball.net/projects/markdown/).",
149+
DefaultValue: DefaultDeprecationReason,
150+
},
151+
},
152+
Locations: []string{
153+
DirectiveLocationFieldDefinition,
154+
DirectiveLocationEnumValue,
155+
},
156+
})

directives_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,6 @@ func TestDirectivesWorksOnInlineFragmentIfFalseOmitsInlineFragment(t *testing.T)
342342
b
343343
}
344344
}
345-
fragment Frag on TestType {
346-
b
347-
}
348345
`
349346
expected := &graphql.Result{
350347
Data: map[string]interface{}{
@@ -368,9 +365,6 @@ func TestDirectivesWorksOnInlineFragmentIfTrueIncludesInlineFragment(t *testing.
368365
b
369366
}
370367
}
371-
fragment Frag on TestType {
372-
b
373-
}
374368
`
375369
expected := &graphql.Result{
376370
Data: map[string]interface{}{
@@ -395,9 +389,6 @@ func TestDirectivesWorksOnInlineFragmentUnlessFalseIncludesInlineFragment(t *tes
395389
b
396390
}
397391
}
398-
fragment Frag on TestType {
399-
b
400-
}
401392
`
402393
expected := &graphql.Result{
403394
Data: map[string]interface{}{
@@ -422,9 +413,6 @@ func TestDirectivesWorksOnInlineFragmentUnlessTrueIncludesInlineFragment(t *test
422413
b
423414
}
424415
}
425-
fragment Frag on TestType {
426-
b
427-
}
428416
`
429417
expected := &graphql.Result{
430418
Data: map[string]interface{}{

executor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ func completeAbstractValue(eCtx *ExecutionContext, returnType Abstract, fieldAST
696696
}
697697

698698
err := invariant(runtimeType != nil,
699-
fmt.Sprintf(`Could not determine runtime type of value "%v" for field %v.%v.`, result, info.ParentType, info.FieldName),
699+
fmt.Sprintf(`Abstract type %v must resolve to an Object type at runtime `+
700+
`for field %v.%v with value "%v", received "%v".`,
701+
returnType, info.ParentType, info.FieldName, result, runtimeType),
700702
)
701703
if err != nil {
702704
panic(err)

0 commit comments

Comments
 (0)