Example #1
0
func parseField(p *Parser) stateFn {

	t := p.next()
	if !p.expect(t, token.String) {
		return nil
	}
	var field ast.Field
	field.Parent = p.prnt
	if p.peek().Type == token.Colon {
		field.Alias = ast.GraphQLName(t.Text)
		p.next()
		field.Name = ast.GraphQLName(p.next().Text)
	} else {
		field.Name = ast.GraphQLName(t.Text)
	}

	if p.prnt == nil {
		def := p.Document.Definitions[len(p.Document.Definitions)-1]
		def.AddSelection(&field)
	} else {
		p.prnt.AddSelection(&field)
	}
	if p.peek().Type == token.Elipsis {
		return parseSelection
	} else {
		p.ptr = &field
		return parseArguments

	}

}
Example #2
0
func parseFragmentSpread(p *Parser) stateFn {

	t := p.next()
	frag := ast.Fragment{FragmentName: ast.GraphQLName(t.Text)}
	p.prnt.AddSelection(&frag)
	p.ptr = &frag

	return parseDirectives
}
Example #3
0
func parseInlineFragment(p *Parser) stateFn {
	p.next()
	t := p.next()

	frag := ast.Fragment{TypeCondition: ast.GraphQLName(t.Text)}
	p.prnt.AddSelection(&frag)
	p.ptr = &frag
	if p.peek().Type == token.Directive {
		return parseDirectives
	}
	return nil
}
Example #4
0
func parseFragmentDefinition(p *Parser) stateFn {
	if !p.expect(p.next(), token.FragmentStart) {
		return nil
	}
	var frag ast.Fragment
	t := p.next()
	if !p.expect(t, token.String) {
		return nil
	} else {
		frag.FragmentName = ast.GraphQLName(string(t.Text))
	}
	p.Document.Definitions = append(p.Document.Definitions, &frag)
	if !p.expect(p.next(), token.On) {
		return nil
	} else {
		t = p.next()
		if !p.expect(t, token.String) {
			return nil
		} else {
			frag.TypeCondition = ast.GraphQLName(string(t.Text))
		}
	}
	return parseDirectives
}
Example #5
0
// parseOperation
func parseOperation(p *Parser) stateFn {
	t := p.next()
	var op ast.Operation

	if t.Type == token.MutationStart {
		op.OperationType = ast.Mutation
	} else {
		op.OperationType = ast.Query
	}
	if t.Type == token.QueryStart {
		op.Name = ast.GraphQLName(p.next().Text)
	}
	p.Document.Definitions = append(p.Document.Definitions, &op)

	return parseVariables
}