コード例 #1
0
func TestSchemaPrinter_PrintsMinimalAST(t *testing.T) {
	astDoc := ast.NewScalarTypeDefinition(&ast.ScalarTypeDefinition{
		Name: ast.NewName(&ast.Name{
			Value: "foo",
		}),
	})
	results := printer.Print(astDoc)
	expected := "scalar foo"
	if !reflect.DeepEqual(results, expected) {
		t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, results))
	}
}
コード例 #2
0
ファイル: parser.go プロジェクト: thanzen/graphql-go
func parseScalarTypeDefinition(parser *Parser) (*ast.ScalarTypeDefinition, error) {
	start := parser.Token.Start
	_, err := expectKeyWord(parser, "scalar")
	if err != nil {
		return nil, err
	}
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	def := ast.NewScalarTypeDefinition(&ast.ScalarTypeDefinition{
		Name: name,
		Loc:  loc(parser, start),
	})
	return def, nil
}
コード例 #3
0
func TestSchemaParser_Scalar(t *testing.T) {
	body := `scalar Hello`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: loc(0, 12),
		Definitions: []ast.Node{
			ast.NewScalarTypeDefinition(&ast.ScalarTypeDefinition{
				Loc: loc(0, 12),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   loc(7, 12),
				}),
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}