graph-gophers / graphql-go

GraphQL server with a focus on ease of use
BSD 2-Clause "Simplified" License
4.64k stars 491 forks source link

query parser bug #617

Closed Boyce-Lee closed 12 months ago

Boyce-Lee commented 1 year ago

query definition: OperationType Name_opt VariablesDefinition_opt Directivesopt SelectionSet detail in gql spec query parser logic is wrong: https://github.com/graph-gophers/graphql-go/blob/master/internal/query/query.go

func parseOperation(l *common.Lexer, opType ast.OperationType) *ast.OperationDefinition {
    op := &ast.OperationDefinition{Type: opType}
    op.Name.Loc = l.Location()
    if l.Peek() == scanner.Ident {
        op.Name = l.ConsumeIdentWithLoc()
    }
    op.Directives = common.ParseDirectives(l)  // wrong point => should ParseDirectives after ParseInputValue
    if l.Peek() == '(' {
        l.ConsumeToken('(')
        for l.Peek() != ')' {
            loc := l.Location()
            l.ConsumeToken('$')
            iv := common.ParseInputValue(l)
            iv.Loc = loc
            op.Vars = append(op.Vars, iv)
        }
        l.ConsumeToken(')')
    }
    op.Selections = parseSelectionSet(l)
    return op
}
pavelnikolov commented 12 months ago

Fixed in this commit. Thank you for reporting this.