本文整理匯總了Golang中github.com/housinganywhere/graphql/testutil.TestParse函數的典型用法代碼示例。如果您正苦於以下問題:Golang TestParse函數的具體用法?Golang TestParse怎麽用?Golang TestParse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了TestParse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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))
}
}
示例2: TestVariables_ListsAndNullability_AllowsListsToContainValues
func TestVariables_ListsAndNullability_AllowsListsToContainValues(t *testing.T) {
doc := `
query q($input: [String]) {
list(input: $input)
}
`
params := map[string]interface{}{
"input": []interface{}{"A"},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"list": `["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))
}
}
示例3: TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull
func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull(t *testing.T) {
doc := `
query Q { nonNullPromise }
`
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
{
Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`,
Locations: []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))
}
}
示例4: 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))
}
}
示例5: 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{
{
Message: `Variable "$input" of required type "[String]!" was not provided.`,
Locations: []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))
}
}
示例6: TestVariables_ObjectsAndNullability_UsingInlineStructs_ProperlyRunsParseLiteralOnComplexScalarTypes
func TestVariables_ObjectsAndNullability_UsingInlineStructs_ProperlyRunsParseLiteralOnComplexScalarTypes(t *testing.T) {
doc := `
{
fieldWithObjectInput(input: {a: "foo", d: "SerializedValue"})
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"a":"foo","d":"DeserializedValue"}`,
},
}
// 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))
}
}
示例7: 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))
}
}
示例8: 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))
}
}
示例9: 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))
}
}
示例10: 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))
}
}
示例11: 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))
}
}
示例12: 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))
}
}
示例13: testVariables_ObjectsAndNullability_UsingVariables_GetAST
func testVariables_ObjectsAndNullability_UsingVariables_GetAST(t *testing.T) *ast.Document {
doc := `
query q($input: TestInputObject) {
fieldWithObjectInput(input: $input)
}
`
return testutil.TestParse(t, doc)
}
示例14: 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{}, error) {
resolvedArgs = p.Args
return resolvedArgs, nil
},
},
},
}),
})
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"])
}
}
示例15: 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)
}