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

Mutation not creating query yaml file #372

Closed
magicMustard opened this issue Jun 26, 2022 · 8 comments
Closed

Mutation not creating query yaml file #372

magicMustard opened this issue Jun 26, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@magicMustard
Copy link

What version of GraphJin are you using? graphjin version

v0.20.4

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

Linux, Intel 6core, 16 gb.

Steps to reproduce the issue (config used to run GraphJin).

`db, err := sql.Open("pgx", DsnStrBuilder())
if err != nil {
log.Fatal(err)
}

conf := &core.Config{
	DisableAllowList: false,
	Production:       false,
	Roles: []core.Role{
		{
			Name: "anon",
			Tables: []core.RoleTable{
				{
					Name:   "users",
					Schema: "rover",
					Query: &core.Query{
						Columns: []string{
							"id",
						},
					},
					Insert: &core.Insert{
						Columns: []string{
							"id",
							"first_name",
						},
					},
				},
			},
		},
	},
}

sg, err := core.NewGraphJin(conf, db)

if err != nil {
	log.Fatal(err)
}

//query := `query findUsers{}`

query := `mutation createUser {
	users(insert: $data) {}
}`

vars := json.RawMessage(`{
	"data": {
		"id": "01G6GZ1MN8EQ9PAQHR0KR809CV",
		"first_name": "Tim",
		"last_name": "somethign",
		"email": "woiefe",
		"phone": "04506gerge"
	}
}`)

ctx := context.Background()

res, err := sg.GraphQL(ctx, query, vars, nil)

if err != nil {
	log.Fatal(err)
}

var data interface{}

if err = jsoniter.Unmarshal(res.Data, &data); err != nil {
	log.Println(err)
}

spew.Dump(data)`

I'm just doing some crude testing and I've created a mutation called "createUser" - however it does not seem to be creating a query.yaml file for said mutation.

When I change the confid to production to force use the allow list, it complains that the mutation does not exist.

Am I doing something wrong?

Expected behaviour and actual result.

I suspect it should be creating a mutation query file?

Correct me if I'm wrong.

@magicMustard magicMustard added the bug Something isn't working label Jun 26, 2022
@magicMustard
Copy link
Author

Noting it created the "findUsers" perfectly fine

@ehsanonline
Copy link
Contributor

maybe this helps: #361 (comment)

@magicMustard
Copy link
Author

I did see that comment yesterday and tried testing it.

However, when I have it non-production mode meaning it should generate the query files, it is not creating the mutation query.

@ehsanonline
Copy link
Contributor

ehsanonline commented Jun 27, 2022

test it with different mutations. remove all comments in your query. only if the mutation executes successfully it will create the query file.
empty response is not allowed in GraphQL, at least return one field like id :

query := `mutation createUser {
	users(insert: $data) {
          id
        }
}`

@magicMustard
Copy link
Author

magicMustard commented Jun 27, 2022

Not sure what to say. Still getting the same thing:

query := mutation createPolicy { policy_groups(insert: $data) {} }

vars := json.RawMessage(`{
	"data": {
		"id": "01G6GZ1MN8EQ9PAQHR0KR809CV",
		"group_type": "ACCOUNT",
		"group_name": "Test"
	}
}`)

image

@ehsanonline
Copy link
Contributor

ehsanonline commented Jun 27, 2022

change query to this:

mutation createPolicy { policy_groups(insert: $data) {   id   } }

and if this dosen't work, please send the error from log. the err variable from sg.GraphQL

@magicMustard
Copy link
Author

Okay, I think I got it, missing at least a query parameter of id or something else appears to empty the query

@magicMustard
Copy link
Author

Thank you ehsan, you were very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants