本文整理汇总了Golang中github.com/graphql-go/graphql/testutil.ContainSubset函数的典型用法代码示例。如果您正苦于以下问题:Golang ContainSubset函数的具体用法?Golang ContainSubset怎么用?Golang ContainSubset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ContainSubset函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestIntrospection_IdentifiesDeprecatedFields
func TestIntrospection_IdentifiesDeprecatedFields(t *testing.T) {
testType := graphql.NewObject(graphql.ObjectConfig{
Name: "TestType",
Fields: graphql.Fields{
"nonDeprecated": &graphql.Field{
Type: graphql.String,
},
"deprecated": &graphql.Field{
Type: graphql.String,
DeprecationReason: "Removed in 1.0",
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: testType,
})
if err != nil {
t.Fatalf("Error creating Schema: %v", err.Error())
}
query := `
{
__type(name: "TestType") {
name
fields(includeDeprecated: true) {
name
isDeprecated,
deprecationReason
}
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"__type": map[string]interface{}{
"name": "TestType",
"fields": []interface{}{
map[string]interface{}{
"name": "nonDeprecated",
"isDeprecated": false,
"deprecationReason": nil,
},
map[string]interface{}{
"name": "deprecated",
"isDeprecated": true,
"deprecationReason": "Removed in 1.0",
},
},
},
},
}
result := g(t, graphql.Params{
Schema: schema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expected.Data.(map[string]interface{})) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例2: TestMutation_IntrospectsCorrectly_ContainsCorrectPayload
func TestMutation_IntrospectsCorrectly_ContainsCorrectPayload(t *testing.T) {
query := `{
__type(name: "SimpleMutationPayload") {
name
kind
fields {
name
type {
name
kind
ofType {
name
kind
}
}
}
}
}`
expected := &graphql.Result{
Data: map[string]interface{}{
"__type": map[string]interface{}{
"name": "SimpleMutationPayload",
"kind": "OBJECT",
"fields": []interface{}{
map[string]interface{}{
"name": "result",
"type": map[string]interface{}{
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
map[string]interface{}{
"name": "clientMutationId",
"type": map[string]interface{}{
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "String",
"kind": "SCALAR",
},
},
},
},
},
},
}
result := graphql.Graphql(graphql.Params{
Schema: mutationTestSchema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expected.Data.(map[string]interface{})) {
t.Fatalf("unexpected, result does not contain subset of expected data")
}
}
示例3: TestSubset_ComplexMixed
func TestSubset_ComplexMixed(t *testing.T) {
super := map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
"d": map[string]interface{}{
"aa": "11",
"bb": "22",
"cc": []interface{}{
"ttt", "rrr", "sss",
},
},
"e": []interface{}{
"111", "222", "333",
},
"f": []interface{}{
[]interface{}{
"9999", "8888", "7777",
},
[]interface{}{
"6666", "5555", "4444",
},
},
}
sub := map[string]interface{}{
"c": "3",
"d": map[string]interface{}{
"bb": "22",
"cc": []interface{}{
"sss",
},
},
"e": []interface{}{
"111",
},
"f": []interface{}{
[]interface{}{
"8888", "9999",
},
[]interface{}{
"4444",
},
},
}
if !testutil.ContainSubset(super, sub) {
t.Fatalf("expected map to be subset of super, got false")
}
}
示例4: TestSubset_Simple_Fail
func TestSubset_Simple_Fail(t *testing.T) {
super := map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
}
sub := map[string]interface{}{
"d": "3",
}
if testutil.ContainSubset(super, sub) {
t.Fatalf("expected map to not be subset of super, got true")
}
}
示例5: TestSubset_NestedSlice
func TestSubset_NestedSlice(t *testing.T) {
super := map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
"d": []interface{}{
"11", "22",
},
}
sub := map[string]interface{}{
"c": "3",
"d": []interface{}{
"11",
},
}
if !testutil.ContainSubset(super, sub) {
t.Fatalf("expected map to be subset of super, got false")
}
}
示例6: TestSubset_NestedMap_Fail
func TestSubset_NestedMap_Fail(t *testing.T) {
super := map[string]interface{}{
"a": "1",
"b": "2",
"c": "3",
"d": map[string]interface{}{
"aa": "11",
"bb": "22",
"cc": "33",
},
}
sub := map[string]interface{}{
"c": "3",
"d": map[string]interface{}{
"dd": "44",
},
}
if testutil.ContainSubset(super, sub) {
t.Fatalf("expected map to not be subset of super, got true")
}
}
示例7: TestIntrospection_ExecutesAnInputObject
//.........这里部分代码省略.........
},
},
})
testType := graphql.NewObject(graphql.ObjectConfig{
Name: "TestType",
Fields: graphql.Fields{
"field": &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
"complex": &graphql.ArgumentConfig{
Type: testInputObject,
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return p.Args["complex"], nil
},
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: testType,
})
if err != nil {
t.Fatalf("Error creating Schema: %v", err.Error())
}
query := `
{
__schema {
types {
kind
name
inputFields {
name
type { ...TypeRef }
defaultValue
}
}
}
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
`
expectedDataSubSet := map[string]interface{}{
"__schema": map[string]interface{}{
"types": []interface{}{
map[string]interface{}{
"kind": "INPUT_OBJECT",
"name": "TestInputObject",
"inputFields": []interface{}{
map[string]interface{}{
"name": "a",
"type": map[string]interface{}{
"kind": "SCALAR",
"name": "String",
"ofType": nil,
},
"defaultValue": `"foo"`,
},
map[string]interface{}{
"name": "b",
"type": map[string]interface{}{
"kind": "LIST",
"name": nil,
"ofType": map[string]interface{}{
"kind": "SCALAR",
"name": "String",
"ofType": nil,
},
},
"defaultValue": nil,
},
},
},
},
},
}
result := g(t, graphql.Params{
Schema: schema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expectedDataSubSet) {
t.Fatalf("unexpected, result does not contain subset of expected data")
}
}
示例8: TestIntrospection_ExecutesAnIntrospectionQuery
//.........这里部分代码省略.........
map[string]interface{}{
"name": "MUTATION",
"isDeprecated": false,
"deprecationReason": nil,
},
map[string]interface{}{
"name": "SUBSCRIPTION",
"isDeprecated": false,
"deprecationReason": nil,
},
map[string]interface{}{
"name": "FIELD",
"isDeprecated": false,
"deprecationReason": nil,
},
map[string]interface{}{
"name": "FRAGMENT_DEFINITION",
"isDeprecated": false,
"deprecationReason": nil,
},
map[string]interface{}{
"name": "FRAGMENT_SPREAD",
"isDeprecated": false,
"deprecationReason": nil,
},
map[string]interface{}{
"name": "INLINE_FRAGMENT",
"isDeprecated": false,
"deprecationReason": nil,
},
},
"possibleTypes": nil,
},
},
"directives": []interface{}{
map[string]interface{}{
"name": "include",
"locations": []interface{}{
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT",
},
"args": []interface{}{
map[string]interface{}{
"defaultValue": nil,
"name": "if",
"type": map[string]interface{}{
"kind": "NON_NULL",
"name": nil,
"ofType": map[string]interface{}{
"kind": "SCALAR",
"name": "Boolean",
"ofType": nil,
},
},
},
},
// deprecated, but included for coverage till removed
"onOperation": false,
"onFragment": true,
"onField": true,
},
map[string]interface{}{
"name": "skip",
"locations": []interface{}{
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT",
},
"args": []interface{}{
map[string]interface{}{
"defaultValue": nil,
"name": "if",
"type": map[string]interface{}{
"kind": "NON_NULL",
"name": nil,
"ofType": map[string]interface{}{
"kind": "SCALAR",
"name": "Boolean",
"ofType": nil,
},
},
},
},
// deprecated, but included for coverage till removed
"onOperation": false,
"onFragment": true,
"onField": true,
},
},
},
}
result := g(t, graphql.Params{
Schema: emptySchema,
RequestString: testutil.IntrospectionQuery,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expectedDataSubSet) {
t.Fatalf("unexpected, result does not contain subset of expected data")
}
}
示例9: TestIntrospection_ExposesDescriptionsOnEnums
func TestIntrospection_ExposesDescriptionsOnEnums(t *testing.T) {
queryRoot := graphql.NewObject(graphql.ObjectConfig{
Name: "QueryRoot",
Fields: graphql.Fields{
"onlyField": &graphql.Field{
Type: graphql.String,
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: queryRoot,
})
if err != nil {
t.Fatalf("Error creating Schema: %v", err.Error())
}
query := `
{
typeKindType: __type(name: "__TypeKind") {
name,
description,
enumValues {
name,
description
}
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"typeKindType": map[string]interface{}{
"name": "__TypeKind",
"description": "An enum describing what kind of type a given `__Type` is",
"enumValues": []interface{}{
map[string]interface{}{
"name": "SCALAR",
"description": "Indicates this type is a scalar.",
},
map[string]interface{}{
"name": "OBJECT",
"description": "Indicates this type is an object. `fields` and `interfaces` are valid fields.",
},
map[string]interface{}{
"name": "INTERFACE",
"description": "Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.",
},
map[string]interface{}{
"name": "UNION",
"description": "Indicates this type is a union. `possibleTypes` is a valid field.",
},
map[string]interface{}{
"name": "ENUM",
"description": "Indicates this type is an enum. `enumValues` is a valid field.",
},
map[string]interface{}{
"name": "INPUT_OBJECT",
"description": "Indicates this type is an input object. `inputFields` is a valid field.",
},
map[string]interface{}{
"name": "LIST",
"description": "Indicates this type is a list. `ofType` is a valid field.",
},
map[string]interface{}{
"name": "NON_NULL",
"description": "Indicates this type is a non-null. `ofType` is a valid field.",
},
},
},
},
}
result := g(t, graphql.Params{
Schema: schema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expected.Data.(map[string]interface{})) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例10: TestIntrospection_ExposesDescriptionsOnTypesAndFields
func TestIntrospection_ExposesDescriptionsOnTypesAndFields(t *testing.T) {
queryRoot := graphql.NewObject(graphql.ObjectConfig{
Name: "QueryRoot",
Fields: graphql.Fields{
"onlyField": &graphql.Field{
Type: graphql.String,
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: queryRoot,
})
if err != nil {
t.Fatalf("Error creating Schema: %v", err.Error())
}
query := `
{
schemaType: __type(name: "__Schema") {
name,
description,
fields {
name,
description
}
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"schemaType": map[string]interface{}{
"name": "__Schema",
"description": `A GraphQL Schema defines the capabilities of a GraphQL ` +
`server. It exposes all available types and directives on ` +
`the server, as well as the entry points for query, mutation, ` +
`and subscription operations.`,
"fields": []interface{}{
map[string]interface{}{
"name": "types",
"description": "A list of all types supported by this server.",
},
map[string]interface{}{
"name": "queryType",
"description": "The type that query operations will be rooted at.",
},
map[string]interface{}{
"name": "mutationType",
"description": "If this server supports mutation, the type that " +
"mutation operations will be rooted at.",
},
map[string]interface{}{
"name": "subscriptionType",
"description": "If this server supports subscription, the type that " +
"subscription operations will be rooted at.",
},
map[string]interface{}{
"name": "directives",
"description": "A list of all directives supported by this server.",
},
},
},
},
}
result := g(t, graphql.Params{
Schema: schema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expected.Data.(map[string]interface{})) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例11: TestIntrospection_RespectsTheIncludeDeprecatedParameterForEnumValues
func TestIntrospection_RespectsTheIncludeDeprecatedParameterForEnumValues(t *testing.T) {
testEnum := graphql.NewEnum(graphql.EnumConfig{
Name: "TestEnum",
Values: graphql.EnumValueConfigMap{
"NONDEPRECATED": &graphql.EnumValueConfig{
Value: 0,
},
"DEPRECATED": &graphql.EnumValueConfig{
Value: 1,
DeprecationReason: "Removed in 1.0",
},
"ALSONONDEPRECATED": &graphql.EnumValueConfig{
Value: 2,
},
},
})
testType := graphql.NewObject(graphql.ObjectConfig{
Name: "TestType",
Fields: graphql.Fields{
"testEnum": &graphql.Field{
Type: testEnum,
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: testType,
})
if err != nil {
t.Fatalf("Error creating Schema: %v", err.Error())
}
query := `
{
__type(name: "TestEnum") {
name
trueValues: enumValues(includeDeprecated: true) {
name
}
falseValues: enumValues(includeDeprecated: false) {
name
}
omittedValues: enumValues {
name
}
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"__type": map[string]interface{}{
"name": "TestEnum",
"trueValues": []interface{}{
map[string]interface{}{
"name": "NONDEPRECATED",
},
map[string]interface{}{
"name": "DEPRECATED",
},
map[string]interface{}{
"name": "ALSONONDEPRECATED",
},
},
"falseValues": []interface{}{
map[string]interface{}{
"name": "NONDEPRECATED",
},
map[string]interface{}{
"name": "ALSONONDEPRECATED",
},
},
"omittedValues": []interface{}{
map[string]interface{}{
"name": "NONDEPRECATED",
},
map[string]interface{}{
"name": "ALSONONDEPRECATED",
},
},
},
},
}
result := g(t, graphql.Params{
Schema: schema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expected.Data.(map[string]interface{})) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例12: TestMutation_IntrospectsCorrectly_ContainsCorrectField
func TestMutation_IntrospectsCorrectly_ContainsCorrectField(t *testing.T) {
query := `{
__schema {
mutationType {
fields {
name
args {
name
type {
name
kind
ofType {
name
kind
}
}
}
type {
name
kind
}
}
}
}
}`
expected := &graphql.Result{
Data: map[string]interface{}{
"__schema": map[string]interface{}{
"mutationType": map[string]interface{}{
"fields": []interface{}{
map[string]interface{}{
"name": "simpleMutation",
"args": []interface{}{
map[string]interface{}{
"name": "input",
"type": map[string]interface{}{
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "SimpleMutationInput",
"kind": "INPUT_OBJECT",
},
},
},
},
"type": map[string]interface{}{
"name": "SimpleMutationPayload",
"kind": "OBJECT",
},
},
map[string]interface{}{
"name": "simplePromiseMutation",
"args": []interface{}{
map[string]interface{}{
"name": "input",
"type": map[string]interface{}{
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "SimplePromiseMutationInput",
"kind": "INPUT_OBJECT",
},
},
},
},
"type": map[string]interface{}{
"name": "SimplePromiseMutationPayload",
"kind": "OBJECT",
},
},
},
},
},
},
}
result := graphql.Graphql(graphql.Params{
Schema: mutationTestSchema,
RequestString: query,
})
if !testutil.ContainSubset(result.Data.(map[string]interface{}), expected.Data.(map[string]interface{})) {
t.Fatalf("unexpected, result does not contain subset of expected data")
}
}
示例13: TestUnionIntersectionTypes_CanIntrospectOnUnionAndIntersectionTypes
func TestUnionIntersectionTypes_CanIntrospectOnUnionAndIntersectionTypes(t *testing.T) {
doc := `
{
Named: __type(name: "Named") {
kind
name
fields { name }
interfaces { name }
possibleTypes { name }
enumValues { name }
inputFields { name }
}
Pet: __type(name: "Pet") {
kind
name
fields { name }
interfaces { name }
possibleTypes { name }
enumValues { name }
inputFields { name }
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"Named": map[string]interface{}{
"kind": "INTERFACE",
"name": "Named",
"fields": []interface{}{
map[string]interface{}{
"name": "name",
},
},
"interfaces": nil,
"possibleTypes": []interface{}{
map[string]interface{}{
"name": "Dog",
},
map[string]interface{}{
"name": "Cat",
},
map[string]interface{}{
"name": "Person",
},
},
"enumValues": nil,
"inputFields": nil,
},
"Pet": map[string]interface{}{
"kind": "UNION",
"name": "Pet",
"fields": nil,
"interfaces": nil,
"possibleTypes": []interface{}{
map[string]interface{}{
"name": "Dog",
},
map[string]interface{}{
"name": "Cat",
},
},
"enumValues": nil,
"inputFields": nil,
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: unionInterfaceTestSchema,
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 !testutil.ContainSubset(expected.Data.(map[string]interface{}), result.Data.(map[string]interface{})) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Data, result.Data))
}
}