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


Golang ast.NewNamed函数代码示例

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


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

示例1: TestSchemaParser_UnionWithTwoTypes

func TestSchemaParser_UnionWithTwoTypes(t *testing.T) {
	body := `union Hello = Wo | Rld`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(0, 22),
		Definitions: []ast.Node{
			ast.NewUnionDefinition(&ast.UnionDefinition{
				Loc: testLoc(0, 22),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(6, 11),
				}),
				Types: []*ast.Named{
					ast.NewNamed(&ast.Named{
						Loc: testLoc(14, 16),
						Name: ast.NewName(&ast.Name{
							Value: "Wo",
							Loc:   testLoc(14, 16),
						}),
					}),
					ast.NewNamed(&ast.Named{
						Loc: testLoc(19, 22),
						Name: ast.NewName(&ast.Name{
							Value: "Rld",
							Loc:   testLoc(19, 22),
						}),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:35,代码来源:schema_parser_test.go

示例2: TestSchemaParser_SimpleFieldWithListArg

func TestSchemaParser_SimpleFieldWithListArg(t *testing.T) {
	body := `
type Hello {
  world(things: [String]): String
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 49),
		Definitions: []ast.Node{
			ast.NewObjectDefinition(&ast.ObjectDefinition{
				Loc: testLoc(1, 49),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(6, 11),
				}),
				Interfaces: []*ast.Named{},
				Fields: []*ast.FieldDefinition{
					ast.NewFieldDefinition(&ast.FieldDefinition{
						Loc: testLoc(16, 47),
						Name: ast.NewName(&ast.Name{
							Value: "world",
							Loc:   testLoc(16, 21),
						}),
						Arguments: []*ast.InputValueDefinition{
							ast.NewInputValueDefinition(&ast.InputValueDefinition{
								Loc: testLoc(22, 38),
								Name: ast.NewName(&ast.Name{
									Value: "things",
									Loc:   testLoc(22, 28),
								}),
								Type: ast.NewList(&ast.List{
									Loc: testLoc(30, 38),
									Type: ast.NewNamed(&ast.Named{
										Loc: testLoc(31, 37),
										Name: ast.NewName(&ast.Name{
											Value: "String",
											Loc:   testLoc(31, 37),
										}),
									}),
								}),
								DefaultValue: nil,
							}),
						},
						Type: ast.NewNamed(&ast.Named{
							Loc: testLoc(41, 47),
							Name: ast.NewName(&ast.Name{
								Value: "String",
								Loc:   testLoc(41, 47),
							}),
						}),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:59,代码来源:schema_parser_test.go

示例3: TestSchemaParser_SimpleFieldWithArgWithDefaultValue

func TestSchemaParser_SimpleFieldWithArgWithDefaultValue(t *testing.T) {
	body := `
type Hello {
  world(flag: Boolean = true): String
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 53),
		Definitions: []ast.Node{
			ast.NewObjectDefinition(&ast.ObjectDefinition{
				Loc: testLoc(1, 53),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(6, 11),
				}),
				Interfaces: []*ast.Named{},
				Fields: []*ast.FieldDefinition{
					ast.NewFieldDefinition(&ast.FieldDefinition{
						Loc: testLoc(16, 51),
						Name: ast.NewName(&ast.Name{
							Value: "world",
							Loc:   testLoc(16, 21),
						}),
						Arguments: []*ast.InputValueDefinition{
							ast.NewInputValueDefinition(&ast.InputValueDefinition{
								Loc: testLoc(22, 42),
								Name: ast.NewName(&ast.Name{
									Value: "flag",
									Loc:   testLoc(22, 26),
								}),
								Type: ast.NewNamed(&ast.Named{
									Loc: testLoc(28, 35),
									Name: ast.NewName(&ast.Name{
										Value: "Boolean",
										Loc:   testLoc(28, 35),
									}),
								}),
								DefaultValue: ast.NewBooleanValue(&ast.BooleanValue{
									Value: true,
									Loc:   testLoc(38, 42),
								}),
							}),
						},
						Type: ast.NewNamed(&ast.Named{
							Loc: testLoc(45, 51),
							Name: ast.NewName(&ast.Name{
								Value: "String",
								Loc:   testLoc(45, 51),
							}),
						}),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:59,代码来源:schema_parser_test.go

示例4: TestSchemaParser_SimpleTypeInheritingInterface

func TestSchemaParser_SimpleTypeInheritingInterface(t *testing.T) {
	body := `type Hello implements World { }`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(0, 31),
		Definitions: []ast.Node{
			ast.NewObjectDefinition(&ast.ObjectDefinition{
				Loc: testLoc(0, 31),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(5, 10),
				}),
				Interfaces: []*ast.Named{
					ast.NewNamed(&ast.Named{
						Name: ast.NewName(&ast.Name{
							Value: "World",
							Loc:   testLoc(22, 27),
						}),
						Loc: testLoc(22, 27),
					}),
				},
				Fields: []*ast.FieldDefinition{},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:29,代码来源:schema_parser_test.go

示例5: parseNamed

func parseNamed(parser *Parser) (*ast.Named, error) {
	start := parser.Token.Start
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	return ast.NewNamed(&ast.Named{
		Name: name,
		Loc:  loc(parser, start),
	}), nil
}
开发者ID:cerisier,项目名称:graphql,代码行数:11,代码来源:parser.go

示例6: TestSchemaParser_SimpleNonNullType

func TestSchemaParser_SimpleNonNullType(t *testing.T) {

	body := `
type Hello {
  world: String!
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 32),
		Definitions: []ast.Node{
			ast.NewObjectDefinition(&ast.ObjectDefinition{
				Loc: testLoc(1, 32),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(6, 11),
				}),
				Interfaces: []*ast.Named{},
				Fields: []*ast.FieldDefinition{
					ast.NewFieldDefinition(&ast.FieldDefinition{
						Loc: testLoc(16, 30),
						Name: ast.NewName(&ast.Name{
							Value: "world",
							Loc:   testLoc(16, 21),
						}),
						Arguments: []*ast.InputValueDefinition{},
						Type: ast.NewNonNull(&ast.NonNull{
							Kind: "NonNullType",
							Loc:  testLoc(23, 30),
							Type: ast.NewNamed(&ast.Named{
								Loc: testLoc(23, 29),
								Name: ast.NewName(&ast.Name{
									Value: "String",
									Loc:   testLoc(23, 29),
								}),
							}),
						}),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:45,代码来源:schema_parser_test.go

示例7: TestSchemaParser_SimpleExtension

func TestSchemaParser_SimpleExtension(t *testing.T) {

	body := `
extend type Hello {
  world: String
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 38),
		Definitions: []ast.Node{
			ast.NewTypeExtensionDefinition(&ast.TypeExtensionDefinition{
				Loc: testLoc(1, 38),
				Definition: ast.NewObjectDefinition(&ast.ObjectDefinition{
					Loc: testLoc(8, 38),
					Name: ast.NewName(&ast.Name{
						Value: "Hello",
						Loc:   testLoc(13, 18),
					}),
					Interfaces: []*ast.Named{},
					Fields: []*ast.FieldDefinition{
						ast.NewFieldDefinition(&ast.FieldDefinition{
							Loc: testLoc(23, 36),
							Name: ast.NewName(&ast.Name{
								Value: "world",
								Loc:   testLoc(23, 28),
							}),
							Arguments: []*ast.InputValueDefinition{},
							Type: ast.NewNamed(&ast.Named{
								Loc: testLoc(30, 36),
								Name: ast.NewName(&ast.Name{
									Value: "String",
									Loc:   testLoc(30, 36),
								}),
							}),
						}),
					},
				}),
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:44,代码来源:schema_parser_test.go

示例8: TestSchemaParser_SimpleInputObject

func TestSchemaParser_SimpleInputObject(t *testing.T) {
	body := `
input Hello {
  world: String
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 32),
		Definitions: []ast.Node{
			ast.NewInputObjectDefinition(&ast.InputObjectDefinition{
				Loc: testLoc(1, 32),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(7, 12),
				}),
				Fields: []*ast.InputValueDefinition{
					ast.NewInputValueDefinition(&ast.InputValueDefinition{
						Loc: testLoc(17, 30),
						Name: ast.NewName(&ast.Name{
							Value: "world",
							Loc:   testLoc(17, 22),
						}),
						Type: ast.NewNamed(&ast.Named{
							Loc: testLoc(24, 30),
							Name: ast.NewName(&ast.Name{
								Value: "String",
								Loc:   testLoc(24, 30),
							}),
						}),
						DefaultValue: nil,
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:39,代码来源:schema_parser_test.go

示例9: TestSchemaParser_SimpleInterface

func TestSchemaParser_SimpleInterface(t *testing.T) {
	body := `
interface Hello {
  world: String
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 36),
		Definitions: []ast.Node{
			ast.NewInterfaceDefinition(&ast.InterfaceDefinition{
				Loc: testLoc(1, 36),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(11, 16),
				}),
				Fields: []*ast.FieldDefinition{
					ast.NewFieldDefinition(&ast.FieldDefinition{
						Loc: testLoc(21, 34),
						Name: ast.NewName(&ast.Name{
							Value: "world",
							Loc:   testLoc(21, 26),
						}),
						Arguments: []*ast.InputValueDefinition{},
						Type: ast.NewNamed(&ast.Named{
							Loc: testLoc(28, 34),
							Name: ast.NewName(&ast.Name{
								Value: "String",
								Loc:   testLoc(28, 34),
							}),
						}),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:39,代码来源:schema_parser_test.go

示例10: TestSchemaParser_SimpleFieldWithTwoArg

func TestSchemaParser_SimpleFieldWithTwoArg(t *testing.T) {
	body := `
type Hello {
  world(argOne: Boolean, argTwo: Int): String
}`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(1, 61),
		Definitions: []ast.Node{
			ast.NewObjectDefinition(&ast.ObjectDefinition{
				Loc: testLoc(1, 61),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(6, 11),
				}),
				Interfaces: []*ast.Named{},
				Fields: []*ast.FieldDefinition{
					ast.NewFieldDefinition(&ast.FieldDefinition{
						Loc: testLoc(16, 59),
						Name: ast.NewName(&ast.Name{
							Value: "world",
							Loc:   testLoc(16, 21),
						}),
						Arguments: []*ast.InputValueDefinition{
							ast.NewInputValueDefinition(&ast.InputValueDefinition{
								Loc: testLoc(22, 37),
								Name: ast.NewName(&ast.Name{
									Value: "argOne",
									Loc:   testLoc(22, 28),
								}),
								Type: ast.NewNamed(&ast.Named{
									Loc: testLoc(30, 37),
									Name: ast.NewName(&ast.Name{
										Value: "Boolean",
										Loc:   testLoc(30, 37),
									}),
								}),
								DefaultValue: nil,
							}),
							ast.NewInputValueDefinition(&ast.InputValueDefinition{
								Loc: testLoc(39, 50),
								Name: ast.NewName(&ast.Name{
									Value: "argTwo",
									Loc:   testLoc(39, 45),
								}),
								Type: ast.NewNamed(&ast.Named{
									Loc: testLoc(47, 50),
									Name: ast.NewName(&ast.Name{
										Value: "Int",
										Loc:   testLoc(47, 50),
									}),
								}),
								DefaultValue: nil,
							}),
						},
						Type: ast.NewNamed(&ast.Named{
							Loc: testLoc(53, 59),
							Name: ast.NewName(&ast.Name{
								Value: "String",
								Loc:   testLoc(53, 59),
							}),
						}),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
开发者ID:cerisier,项目名称:graphql,代码行数:71,代码来源:schema_parser_test.go


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