本文整理汇总了Golang中github.com/wadeandwendy/graphql/testutil.TestExecute函数的典型用法代码示例。如果您正苦于以下问题:Golang TestExecute函数的具体用法?Golang TestExecute怎么用?Golang TestExecute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TestExecute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestVariables_NullableScalars_AllowsNullableInputsToBeOmittedInAnUnlistedVariable
func TestVariables_NullableScalars_AllowsNullableInputsToBeOmittedInAnUnlistedVariable(t *testing.T) {
doc := `
query SetsNullable {
fieldWithNullableStringInput(input: $value)
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithNullableStringInput": nil,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:27,代码来源:variables_test.go
示例2: TestNonNull_NullsANullableFieldThatSynchronouslyReturnsNullInAPromise
func TestNonNull_NullsANullableFieldThatSynchronouslyReturnsNullInAPromise(t *testing.T) {
doc := `
query Q {
promise
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"promise": nil,
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: nonNullTestSchema,
AST: ast,
Root: nullingData,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected.Data, result.Data) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Data, result.Data))
}
if !reflect.DeepEqual(expected.Errors, result.Errors) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:31,代码来源:nonnull_test.go
示例3: TestVariables_NonNullableScalars_AllowsNonNullableInputsToBeSetToAValueDirectly
func TestVariables_NonNullableScalars_AllowsNonNullableInputsToBeSetToAValueDirectly(t *testing.T) {
doc := `
{
fieldWithNonNullableStringInput(input: "a")
}
`
params := map[string]interface{}{
"value": "a",
}
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithNonNullableStringInput": `"a"`,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:33,代码来源:variables_test.go
示例4: TestVariables_NonNullableScalars_PassesAlongNullForNonNullableInputsIfExplicitlySetInTheQuery
func TestVariables_NonNullableScalars_PassesAlongNullForNonNullableInputsIfExplicitlySetInTheQuery(t *testing.T) {
doc := `
{
fieldWithNonNullableStringInput
}
`
params := map[string]interface{}{
"value": "a",
}
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithNonNullableStringInput": nil,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:33,代码来源:variables_test.go
示例5: TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull
func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull(t *testing.T) {
doc := `
query Q { nonNullPromise }
`
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`,
Locations: []location.SourceLocation{
location.SourceLocation{Line: 2, Column: 17},
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: nonNullTestSchema,
AST: ast,
Root: nullingData,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:32,代码来源:nonnull_test.go
示例6: TestVariables_ListsAndNullability_DoesNotAllowNonNullListsToBeNull
func TestVariables_ListsAndNullability_DoesNotAllowNonNullListsToBeNull(t *testing.T) {
doc := `
query q($input: [String]!) {
nnList(input: $input)
}
`
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: `Variable "$input" of required type "[String]!" was not provided.`,
Locations: []location.SourceLocation{
location.SourceLocation{
Line: 2, Column: 17,
},
},
},
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:34,代码来源:variables_test.go
示例7: TestVariables_UsesArgumentDefaultValues_WhenArgumentProvidedCannotBeParsed
func TestVariables_UsesArgumentDefaultValues_WhenArgumentProvidedCannotBeParsed(t *testing.T) {
doc := `
{
fieldWithDefaultArgumentValue(input: WRONG_TYPE)
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithDefaultArgumentValue": `"Hello World"`,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:26,代码来源:variables_test.go
示例8: TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnIncorrectType
func TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnIncorrectType(t *testing.T) {
params := map[string]interface{}{
"input": "foo bar",
}
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: `Variable "$input" expected value of type "TestInputObject" but ` +
`got: "foo bar".`,
Locations: []location.SourceLocation{
location.SourceLocation{
Line: 2, Column: 17,
},
},
},
},
}
ast := testVariables_ObjectsAndNullability_UsingVariables_GetAST(t)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:35,代码来源:variables_test.go
示例9: TestVariables_ObjectsAndNullability_UsingInlineStructs_ProperlyParsesSingleValueToList
func TestVariables_ObjectsAndNullability_UsingInlineStructs_ProperlyParsesSingleValueToList(t *testing.T) {
doc := `
{
fieldWithObjectInput(input: {a: "foo", b: "bar", c: "baz"})
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"a":"foo","b":["bar"],"c":"baz"}`,
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:27,代码来源:variables_test.go
示例10: TestVariables_ListsAndNullability_AllowsNonNullListsToContainValues
func TestVariables_ListsAndNullability_AllowsNonNullListsToContainValues(t *testing.T) {
doc := `
query q($input: [String]!) {
nnList(input: $input)
}
`
params := map[string]interface{}{
"input": []interface{}{"A"},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nnList": `["A"]`,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:30,代码来源:variables_test.go
示例11: TestVariables_ObjectsAndNullability_UsingVariables_UsesDefaultValueWhenNotProvided
func TestVariables_ObjectsAndNullability_UsingVariables_UsesDefaultValueWhenNotProvided(t *testing.T) {
doc := `
query q($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) {
fieldWithObjectInput(input: $input)
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"a":"foo","b":["bar"],"c":"baz"}`,
},
}
withDefaultsAST := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: withDefaultsAST,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:28,代码来源:variables_test.go
示例12: TestVariables_ObjectsAndNullability_UsingInlineStructs_DoesNotUseIncorrectValue
func TestVariables_ObjectsAndNullability_UsingInlineStructs_DoesNotUseIncorrectValue(t *testing.T) {
doc := `
{
fieldWithObjectInput(input: ["foo", "bar", "baz"])
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": nil,
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:27,代码来源:variables_test.go
示例13: TestVariables_ObjectsAndNullability_UsingVariables_ProperlyParsesSingleValueToList
func TestVariables_ObjectsAndNullability_UsingVariables_ProperlyParsesSingleValueToList(t *testing.T) {
params := map[string]interface{}{
"input": map[string]interface{}{
"a": "foo",
"b": "bar",
"c": "baz",
},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"a":"foo","b":["bar"],"c":"baz"}`,
},
}
ast := testVariables_ObjectsAndNullability_UsingVariables_GetAST(t)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:30,代码来源:variables_test.go
示例14: TestVariables_ObjectsAndNullability_UsingVariables_ExecutesWithComplexScalarInput
func TestVariables_ObjectsAndNullability_UsingVariables_ExecutesWithComplexScalarInput(t *testing.T) {
params := map[string]interface{}{
"input": map[string]interface{}{
"c": "foo",
"d": "SerializedValue",
},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"c":"foo","d":"DeserializedValue"}`,
},
}
ast := testVariables_ObjectsAndNullability_UsingVariables_GetAST(t)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:29,代码来源:variables_test.go
示例15: TestCorrectlyThreadsArguments
func TestCorrectlyThreadsArguments(t *testing.T) {
query := `
query Example {
b(numArg: 123, stringArg: "foo")
}
`
var resolvedArgs map[string]interface{}
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Type",
Fields: graphql.Fields{
"b": &graphql.Field{
Args: graphql.FieldConfigArgument{
"numArg": &graphql.ArgumentConfig{
Type: graphql.Int,
},
"stringArg": &graphql.ArgumentConfig{
Type: graphql.String,
},
},
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) interface{} {
resolvedArgs = p.Args
return resolvedArgs
},
},
},
}),
})
if err != nil {
t.Fatalf("Error in schema %v", err.Error())
}
// parse query
ast := testutil.TestParse(t, query)
// execute
ep := graphql.ExecuteParams{
Schema: schema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
expectedNum := 123
expectedString := "foo"
if resolvedArgs["numArg"] != expectedNum {
t.Fatalf("Expected args.numArg to equal `%v`, got `%v`", expectedNum, resolvedArgs["numArg"])
}
if resolvedArgs["stringArg"] != expectedString {
t.Fatalf("Expected args.stringArg to equal `%v`, got `%v`", expectedNum, resolvedArgs["stringArg"])
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:58,代码来源:executor_test.go
示例16: executeDirectivesTestQuery
func executeDirectivesTestQuery(t *testing.T, doc string) *graphql.Result {
ast := testutil.TestParse(t, doc)
ep := graphql.ExecuteParams{
Schema: directivesTestSchema,
AST: ast,
Root: directivesTestData,
}
return testutil.TestExecute(t, ep)
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:9,代码来源:directives_test.go
示例17: TestAvoidsRecursion
func TestAvoidsRecursion(t *testing.T) {
doc := `
query Q {
a
...Frag
...Frag
}
fragment Frag on Type {
a,
...Frag
}
`
data := map[string]interface{}{
"a": "b",
}
expected := &graphql.Result{
Data: map[string]interface{}{
"a": "b",
},
}
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Type",
Fields: graphql.Fields{
"a": &graphql.Field{
Type: graphql.String,
},
},
}),
})
if err != nil {
t.Fatalf("Error in schema %v", err.Error())
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: schema,
AST: ast,
Root: data,
OperationName: "Q",
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:57,代码来源:executor_test.go
示例18: TestMutations_ExecutionOrdering_EvaluatesMutationsSerially
func TestMutations_ExecutionOrdering_EvaluatesMutationsSerially(t *testing.T) {
root := newTestRoot(6)
doc := `mutation M {
first: immediatelyChangeTheNumber(newNumber: 1) {
theNumber
},
second: promiseToChangeTheNumber(newNumber: 2) {
theNumber
},
third: immediatelyChangeTheNumber(newNumber: 3) {
theNumber
}
fourth: promiseToChangeTheNumber(newNumber: 4) {
theNumber
},
fifth: immediatelyChangeTheNumber(newNumber: 5) {
theNumber
}
}`
expected := &graphql.Result{
Data: map[string]interface{}{
"first": map[string]interface{}{
"theNumber": 1,
},
"second": map[string]interface{}{
"theNumber": 2,
},
"third": map[string]interface{}{
"theNumber": 3,
},
"fourth": map[string]interface{}{
"theNumber": 4,
},
"fifth": map[string]interface{}{
"theNumber": 5,
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: mutationsTestSchema,
AST: ast,
Root: root,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:57,代码来源:mutations_test.go
示例19: TestUnionIntersectionTypes_ExecutesUnionTypesWithInlineFragments
func TestUnionIntersectionTypes_ExecutesUnionTypesWithInlineFragments(t *testing.T) {
// This is the valid version of the query in the above test.
doc := `
{
__typename
name
pets {
__typename
... on Dog {
name
barks
}
... on Cat {
name
meows
}
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"__typename": "Person",
"name": "John",
"pets": []interface{}{
map[string]interface{}{
"__typename": "Cat",
"name": "Garfield",
"meows": false,
},
map[string]interface{}{
"__typename": "Dog",
"name": "Odie",
"barks": true,
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: unionInterfaceTestSchema,
AST: ast,
Root: john,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:54,代码来源:union_interface_test.go
示例20: TestUnionIntersectionTypes_ExecutesUsingInterfaceTypes
func TestUnionIntersectionTypes_ExecutesUsingInterfaceTypes(t *testing.T) {
// NOTE: This is an *invalid* query, but it should be an *executable* query.
doc := `
{
__typename
name
friends {
__typename
name
barks
meows
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"__typename": "Person",
"name": "John",
"friends": []interface{}{
map[string]interface{}{
"__typename": "Person",
"name": "Liz",
},
map[string]interface{}{
"__typename": "Dog",
"name": "Odie",
"barks": true,
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: unionInterfaceTestSchema,
AST: ast,
Root: john,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
开发者ID:wadeandwendy,项目名称:graphql,代码行数:49,代码来源:union_interface_test.go
注:本文中的github.com/wadeandwendy/graphql/testutil.TestExecute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论