当前位置: 首页>>代码示例>>Golang>>正文


Golang graphql.Do函数代码示例

本文整理汇总了Golang中github.com/housinganywhere/graphql.Do函数的典型用法代码示例。如果您正苦于以下问题:Golang Do函数的具体用法?Golang Do怎么用?Golang Do使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Do函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMutateAndGetPayload_AddsErrors

func TestMutateAndGetPayload_AddsErrors(t *testing.T) {
	query := `
        mutation M {
          simpleMutation(input: {clientMutationId: "abc"}) {
            result
            clientMutationId
          }
        }
      `
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"simpleMutation": interface{}(nil),
		},
		Errors: []gqlerrors.FormattedError{
			gqlerrors.FormattedError{
				Message:   NotFoundError.Error(),
				Locations: []location.SourceLocation{},
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        mutationTestSchemaError,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:28,代码来源:mutation_test.go

示例2: main

func main() {
	// Schema
	fields := graphql.Fields{
		"hello": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				return "world", nil
			},
		},
	}
	rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
	schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
	schema, err := graphql.NewSchema(schemaConfig)
	if err != nil {
		log.Fatalf("failed to create new schema, error: %v", err)
	}

	// Query
	query := `
		{
			hello
		}
	`
	params := graphql.Params{Schema: schema, RequestString: query}
	r := graphql.Do(params)
	if len(r.Errors) > 0 {
		log.Fatalf("failed to execute graphql operation, errors: %+v", r.Errors)
	}
	rJSON, _ := json.Marshal(r)
	fmt.Printf("%s \n", rJSON) // {“data”:{“hello”:”world”}}
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:31,代码来源:main.go

示例3: TestGlobalIDFields_RefetchesTheIDs

func TestGlobalIDFields_RefetchesTheIDs(t *testing.T) {
	query := `{
      user: node(id: "VXNlcjox") {
        id
        ... on User {
          name
        }
      },
      photo: node(id: "UGhvdG86MQ==") {
        id
        ... on Photo {
          width
        }
      }
    }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"user": map[string]interface{}{
				"id":   "VXNlcjox",
				"name": "John Doe",
			},
			"photo": map[string]interface{}{
				"id":    "UGhvdG86MQ==",
				"width": 300,
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        globalIDTestSchema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:35,代码来源:node_global_test.go

示例4: TestQuery_ExecutionDoesNotAddErrorsFromFieldResolveFn

func TestQuery_ExecutionDoesNotAddErrorsFromFieldResolveFn(t *testing.T) {
	qError := errors.New("queryError")
	q := graphql.NewObject(graphql.ObjectConfig{
		Name: "Query",
		Fields: graphql.Fields{
			"a": &graphql.Field{
				Type: graphql.String,
				Resolve: func(p graphql.ResolveParams) (interface{}, error) {
					return nil, qError
				},
			},
			"b": &graphql.Field{
				Type: graphql.String,
				Resolve: func(p graphql.ResolveParams) (interface{}, error) {
					return "ok", nil
				},
			},
		},
	})
	blogSchema, err := graphql.NewSchema(graphql.SchemaConfig{
		Query: q,
	})
	if err != nil {
		t.Fatalf("unexpected error, got: %v", err)
	}
	query := "{ b }"
	result := graphql.Do(graphql.Params{
		Schema:        blogSchema,
		RequestString: query,
	})
	if len(result.Errors) != 0 {
		t.Fatalf("wrong result, unexpected errors: %+v", result.Errors)
	}
}
开发者ID:housinganywhere,项目名称:graphql,代码行数:34,代码来源:executor_test.go

示例5: TestConnection_TestFetching_CorrectlyFetchesNoShipsOfTheRebelsAtTheEndOfTheConnection

func TestConnection_TestFetching_CorrectlyFetchesNoShipsOfTheRebelsAtTheEndOfTheConnection(t *testing.T) {
	query := `
        query RebelsQuery {
          rebels {
            name,
            ships(first: 3 after: "YXJyYXljb25uZWN0aW9uOjQ=") {
              edges {
                cursor,
                node {
                  name
                }
              }
            }
          }
        }
      `
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"rebels": map[string]interface{}{
				"name": "Alliance to Restore the Republic",
				"ships": map[string]interface{}{
					"edges": []interface{}{},
				},
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        starwars.Schema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:34,代码来源:connection_test.go

示例6: TestGlobalIDFields_GivesDifferentIDs

func TestGlobalIDFields_GivesDifferentIDs(t *testing.T) {
	query := `{
      allObjects {
        id
      }
    }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"allObjects": []interface{}{
				map[string]interface{}{
					"id": "VXNlcjox",
				},
				map[string]interface{}{
					"id": "VXNlcjoy",
				},
				map[string]interface{}{
					"id": "UGhvdG86MQ==",
				},
				map[string]interface{}{
					"id": "UGhvdG86Mg==",
				},
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        globalIDTestSchema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:32,代码来源:node_global_test.go

示例7: TestPluralIdentifyingRootField_Configuration_ArgNames_WrongArgNameSpecified

func TestPluralIdentifyingRootField_Configuration_ArgNames_WrongArgNameSpecified(t *testing.T) {

	t.Skipf("Pending `validator` implementation")
	query := `{
      usernames(usernamesMisspelled:["dschafer", "leebyron", "schrockn"]) {
        username
        url
      }
    }`
	expected := &graphql.Result{
		Data: nil,
		Errors: []gqlerrors.FormattedError{
			gqlerrors.FormattedError{
				Message: `Unknown argument "usernamesMisspelled" on field "usernames" of type "Query".`,
				Locations: []location.SourceLocation{
					location.SourceLocation{Line: 2, Column: 17},
				},
			},
			gqlerrors.FormattedError{
				Message: `Field "usernames" argument "usernames" of type "[String!]!" is required but not provided.`,
				Locations: []location.SourceLocation{
					location.SourceLocation{Line: 2, Column: 7},
				},
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        pluralTestSchema,
		RequestString: query,
	})
	pretty.Println(result)
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:35,代码来源:plural_test.go

示例8: TestObjectIdentification_TestFetching_CorrectlyRefetchesTheEmpire

func TestObjectIdentification_TestFetching_CorrectlyRefetchesTheEmpire(t *testing.T) {
	query := `
        query EmpireRefetchQuery {
          node(id: "RmFjdGlvbjoy") {
            id
            ... on Faction {
              name
            }
          }
        }
      `
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"node": map[string]interface{}{
				"id":   "RmFjdGlvbjoy",
				"name": "Galactic Empire",
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        starwars.Schema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:27,代码来源:object_identification_test.go

示例9: TestObjectIdentification_TestFetching_CorrectlyFetchesTheIDAndTheNameOfTheRebels

func TestObjectIdentification_TestFetching_CorrectlyFetchesTheIDAndTheNameOfTheRebels(t *testing.T) {
	query := `
        query RebelsQuery {
          rebels {
            id
            name
          }
        }
      `
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"rebels": map[string]interface{}{
				"id":   "RmFjdGlvbjox",
				"name": "Alliance to Restore the Republic",
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        starwars.Schema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:25,代码来源:object_identification_test.go

示例10: TestMutation_WithClientMutationId_BehavesCorrectly_SupportsPromiseMutations

// Async mutation using channels
func TestMutation_WithClientMutationId_BehavesCorrectly_SupportsPromiseMutations(t *testing.T) {
	query := `
        mutation M {
          simplePromiseMutation(input: {clientMutationId: "abc"}) {
            result
            clientMutationId
          }
        }
      `
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"simplePromiseMutation": map[string]interface{}{
				"result":           1,
				"clientMutationId": "abc",
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        mutationTestSchema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:26,代码来源:mutation_test.go

示例11: TestObjectIdentification_TestFetching_CorrectlyRefetchesTheXWing

func TestObjectIdentification_TestFetching_CorrectlyRefetchesTheXWing(t *testing.T) {
	query := `
        query XWingRefetchQuery {
          node(id: "U2hpcDox") {
            id
            ... on Ship {
              name
            }
          }
        }
      `
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"node": map[string]interface{}{
				"id":   "U2hpcDox",
				"name": "X-Wing",
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        starwars.Schema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:27,代码来源:object_identification_test.go

示例12: TestPluralIdentifyingRootField_AllowsFetching

func TestPluralIdentifyingRootField_AllowsFetching(t *testing.T) {
	query := `{
      usernames(usernames:["dschafer", "leebyron", "schrockn"]) {
        username
        url
      }
    }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"usernames": []interface{}{
				map[string]interface{}{
					"username": "dschafer",
					"url":      "www.facebook.com/dschafer",
				},
				map[string]interface{}{
					"username": "leebyron",
					"url":      "www.facebook.com/leebyron",
				},
				map[string]interface{}{
					"username": "schrockn",
					"url":      "www.facebook.com/schrockn",
				},
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        pluralTestSchema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:33,代码来源:plural_test.go

示例13: TestNodeInterfaceAndFields_AllowsRefetching_ReturnsNullForBadIDs

func TestNodeInterfaceAndFields_AllowsRefetching_ReturnsNullForBadIDs(t *testing.T) {
	query := `{
        node(id: "5") {
          id
        }
      }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"node": nil,
		},
		Errors: []gqlerrors.FormattedError{
			{
				Message:   "Unknown node",
				Locations: []location.SourceLocation{},
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        nodeTestSchema,
		RequestString: query,
	})

	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:26,代码来源:node_test.go

示例14: TestNodeInterfaceAndFields_AllowsRefetching_GetsTheCorrectWidthForPhotos

func TestNodeInterfaceAndFields_AllowsRefetching_GetsTheCorrectWidthForPhotos(t *testing.T) {
	query := `{
        node(id: "4") {
          id
          ... on Photo {
            width
          }
        }
      }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"node": map[string]interface{}{
				"id":    "4",
				"width": 400,
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        nodeTestSchema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:25,代码来源:node_test.go

示例15: TestNodeInterfaceAndFields_AllowsRefetching_GetsTheCorrectNameForUsers

func TestNodeInterfaceAndFields_AllowsRefetching_GetsTheCorrectNameForUsers(t *testing.T) {
	query := `{
        node(id: "1") {
          id
          ... on User {
            name
          }
        }
      }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"node": map[string]interface{}{
				"id":   "1",
				"name": "John Doe",
			},
		},
	}
	result := graphql.Do(graphql.Params{
		Schema:        nodeTestSchema,
		RequestString: query,
	})
	if !reflect.DeepEqual(result, expected) {
		t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
	}
}
开发者ID:housinganywhere,项目名称:relay,代码行数:25,代码来源:node_test.go


注:本文中的github.com/housinganywhere/graphql.Do函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。