示例#1
0
func TestPluralIdentifyingRootField_Configuration_ResolveSingleInputIsNil(t *testing.T) {

	var pluralTestQueryType = graphql.NewObject(graphql.ObjectConfig{
		Name: "Query",
		Fields: graphql.Fields{
			"usernames": relay.PluralIdentifyingRootField(relay.PluralIdentifyingRootFieldConfig{
				ArgName:     "usernames",
				Description: "Map from a username to the user",
				InputType:   graphql.String,
				OutputType:  pluralTestUserType,
			}),
		},
	})

	var pluralTestSchema, _ = graphql.NewSchema(graphql.SchemaConfig{
		Query: pluralTestQueryType,
	})

	query := `{
      usernames(usernames:["dschafer", "leebyron", "schrockn"]) {
        username
        url
      }
    }`
	expected := &graphql.Result{
		Data: map[string]interface{}{
			"usernames": nil,
		},
	}
	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))
	}
}
示例#2
0
		},
		"url": &graphql.Field{
			Type: graphql.String,
		},
	},
})

var pluralTestQueryType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Query",
	Fields: graphql.Fields{
		"usernames": relay.PluralIdentifyingRootField(relay.PluralIdentifyingRootFieldConfig{
			ArgName:     "usernames",
			Description: "Map from a username to the user",
			InputType:   graphql.String,
			OutputType:  pluralTestUserType,
			ResolveSingleInput: func(username interface{}) interface{} {
				return map[string]interface{}{
					"username": fmt.Sprintf("%v", username),
					"url":      fmt.Sprintf("www.facebook.com/%v", username),
				}
			},
		}),
	},
})

var pluralTestSchema, _ = graphql.NewSchema(graphql.SchemaConfig{
	Query: pluralTestQueryType,
})

func TestPluralIdentifyingRootField_AllowsFetching(t *testing.T) {
	query := `{
      usernames(usernames:["dschafer", "leebyron", "schrockn"]) {