From 5c3e251e07813db5dc20cd154480b2dc8de71e91 Mon Sep 17 00:00:00 2001 From: Aman Mangal Date: Tue, 25 Jul 2023 16:08:07 +0530 Subject: [PATCH] chore(graphql): upgrade gqlparser to v2.2.2 CLOSES DGRAPHCORE-329 Seems like there was a race condition that was fixed in v2.2.2 from v2.2.1. This change upgrades gqlparser to the fixed version. --- dgraphtest/config.go | 6 ++ dgraphtest/dgraph.go | 4 + go.mod | 2 +- go.sum | 4 +- .../integration2/graphql_schema_auth_test.go | 75 +++++++++++++++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 systest/integration2/graphql_schema_auth_test.go diff --git a/dgraphtest/config.go b/dgraphtest/config.go index 3f356576785..1fa0fe3ad56 100644 --- a/dgraphtest/config.go +++ b/dgraphtest/config.go @@ -94,6 +94,7 @@ type ClusterConfig struct { // exposed port offset for grpc/http port for both alpha/zero portOffset int bulkOutDir string + lambdaURL string } func NewClusterConfig() ClusterConfig { @@ -180,3 +181,8 @@ func (cc ClusterConfig) WithBulkLoadOutDir(dir string) ClusterConfig { cc.bulkOutDir = dir return cc } + +func (cc ClusterConfig) WithGraphqlLambdaURL(url string) ClusterConfig { + cc.lambdaURL = url + return cc +} diff --git a/dgraphtest/dgraph.go b/dgraphtest/dgraph.go index 6a4d1033c88..9c23ab04a58 100644 --- a/dgraphtest/dgraph.go +++ b/dgraphtest/dgraph.go @@ -243,6 +243,10 @@ func (a *alpha) cmd(c *LocalCluster) []string { } acmd = append(acmd, zeroAddrsArg) + if c.conf.lambdaURL != "" { + acmd = append(acmd, fmt.Sprintf(`--graphql=lambda-url=%s`, c.conf.lambdaURL)) + } + return acmd } diff --git a/go.mod b/go.mod index 9f4ce6fbc35..df2224e7546 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/dgraph-io/badger/v4 v4.1.0 github.com/dgraph-io/dgo/v230 v230.0.1 github.com/dgraph-io/gqlgen v0.13.2 - github.com/dgraph-io/gqlparser/v2 v2.2.1 + github.com/dgraph-io/gqlparser/v2 v2.2.2 github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15 github.com/dgraph-io/ristretto v0.1.1 github.com/dgraph-io/simdjson-go v0.3.0 diff --git a/go.sum b/go.sum index 6e9bfb54d7b..a297d7e7029 100644 --- a/go.sum +++ b/go.sum @@ -152,8 +152,8 @@ github.com/dgraph-io/dgo/v230 v230.0.1/go.mod h1:5FerO2h4LPOxR2XTkOAtqUUPaFdQ+5a github.com/dgraph-io/gqlgen v0.13.2 h1:TNhndk+eHKj5qE7BenKKSYdSIdOGhLqxR1rCiMso9KM= github.com/dgraph-io/gqlgen v0.13.2/go.mod h1:iCOrOv9lngN7KAo+jMgvUPVDlYHdf7qDwsTkQby2Sis= github.com/dgraph-io/gqlparser/v2 v2.1.1/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU= -github.com/dgraph-io/gqlparser/v2 v2.2.1 h1:15msK9XEHOSrRqQO48UU+2ZTf1R1U8+tfL9H5D5/eQQ= -github.com/dgraph-io/gqlparser/v2 v2.2.1/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU= +github.com/dgraph-io/gqlparser/v2 v2.2.2 h1:CnxXOKL4EPguKqcGV/z4u4VoW5izUkOTIsNM6xF+0f4= +github.com/dgraph-io/gqlparser/v2 v2.2.2/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU= github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15 h1:X2NRsgAtVUAp2nmTPCq+x+wTcRRrj74CEpy7E0Unsl4= github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ= github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= diff --git a/systest/integration2/graphql_schema_auth_test.go b/systest/integration2/graphql_schema_auth_test.go new file mode 100644 index 00000000000..ec1a5e3925f --- /dev/null +++ b/systest/integration2/graphql_schema_auth_test.go @@ -0,0 +1,75 @@ +//go:build integration2 + +/* + * Copyright 2023 Dgraph Labs, Inc. and Contributors * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "testing" + "time" + + "github.com/dgraph-io/dgraph/dgraphtest" + "github.com/dgraph-io/dgraph/x" + "github.com/stretchr/testify/require" +) + +func TestGraphqlSchema(t *testing.T) { + conf := dgraphtest.NewClusterConfig().WithNumAlphas(2).WithNumZeros(1). + WithACL(time.Hour).WithReplicas(1). + WithGraphqlLambdaURL("http://127.0.0.1/lambda") // dummy URL + c, err := dgraphtest.NewLocalCluster(conf) + require.NoError(t, err) + defer func() { c.Cleanup(t.Failed()) }() + require.NoError(t, c.Start()) + + hc, err := c.HTTPClient() + require.NoError(t, err) + require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser, + dgraphtest.DefaultPassword, x.GalaxyNamespace)) + + //nolint:lll + sch := `type City @auth( + query: { or: [ + { rule: "{$Role: { eq: \"ADMIN\" }}"}, + { rule: """ + query($CITYID: String!) { + queryCity (filter: { + id: { eq: $CITYID } + }){ + name + } + }""" + }] + }, + + add: { rule: "{$Role: { eq: \"ADMIN\" }}"}, + update: { rule: "{$Role: { eq: \"ADMIN\" }}"}, + ){ + id: ID! + name: String! @search(by: [hash, trigram]) + state: String! + country: String! @search(by: [hash, trigram]) + current_weather: String! @lambda + desc: String! @lambda + } + + type Query { + citiesByName(name: String!): [City] @lambda + } + + # Dgraph.Authorization {"VerificationKey":"secretkey","Header":"X-Test-Auth","Namespace":"https://xyz.io/jwt/claims","Algo":"HS256","Audience":["aud"]}` + require.NoError(t, hc.UpdateGQLSchema(sch)) +}