Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for $ in quoted string #4702

Merged
merged 7 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ func substituteVariablesFilter(f *FilterTree, vmap varMap) error {
}

for idx, v := range f.Func.Args {
if !v.IsGraphQLVar {
continue
}
if f.Func.Name == uidFunc {
// This is to support GraphQL variables in uid functions.
idVal, ok := vmap[v.Value]
Expand Down
59 changes: 59 additions & 0 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5136,3 +5136,62 @@ func TestParseExpandFilterErr(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "expand is only compatible with type filters")
}

func TestFilterWithDollar(t *testing.T) {
query := `
{
q(func: eq(name, "Bob"), first:5) @filter(eq(description, "$yo")) {
name
description
}
}
`
gq, err := Parse(Request{
Str: query,
})
require.NoError(t, err)
require.Equal(t, gq.Query[0].Filter.Func.Args[0].Value, "$yo")
}

func TestFilterWithDollarError(t *testing.T) {
query := `
{
q(func: eq(name, "Bob"), first:5) @filter(eq(description, $yo)) {
name
description
}
}
`
_, err := Parse(Request{
Str: query,
})
require.Error(t, err)
}

func TestFilterWithVar(t *testing.T) {
query := `query data($a: string = "dgraph")
{
data(func: eq(name, "Bob"), first:5) @filter(eq(description, $a)) {
name
description
}
}`
gq, err := Parse(Request{
Str: query,
})
require.NoError(t, err)
require.Equal(t, gq.Query[0].Filter.Func.Args[0].Value, "dgraph")
}

func TestFilterWithEmpty(t *testing.T) {
query := `{
names(func: has(name)) @filter(eq(name, "")) {
count(uid)
}
}`
gq, err := Parse(Request{
Str: query,
})
require.NoError(t, err)
require.Equal(t, gq.Query[0].Filter.Func.Args[0].Value, "")
}