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

allow query root in mutation response (close #1583) #1759

Closed

Conversation

rakeshkky
Copy link
Member

Description

Support queries in mutation response.

Example:-

    mutation insert_article {
      insert_article(
        objects: [
          {
            id: 21,
            title: "Article 1",
            content: "Sample article content",
            author_id: 3
          }
        ]
      ) {
        returning {
          id
          title
        }
        query {
          author(where: {id: {_eq: 1}){
            id
            name
          }
        }
      }
    }

Response:-

    {
      "data": {
        "insert_article": {
          "affected_rows": 1,
          "returning": [
            {
              "id": 21,
              "title": "Article 1"
            }
          ],
          "query": {
            "author": [
              {
                "id": 1,
                "name": "Author 1"
              }
            ]
          }
        }
      }
    }

Affected components

  • Server
  • Docs
  • Tests

Related Issues

close #1583

@rakeshkky rakeshkky added c/server Related to server c/docs Related to docs labels Mar 13, 2019
@rakeshkky rakeshkky self-assigned this Mar 13, 2019
@hasura-bot
Copy link
Contributor

Review app for commit 235d5c0 deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-235d5c0

mutationRootTy = G.NamedType "mutation_root"

subscriptionRootTy :: G.NamedType
subscriptionRootTy = G.NamedType "subscription_root"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better naming would be queryRootName, mutationRootName etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since those functions give G.NamedType I name them as .....Ty. ...Name is suitable if functions give G.Name.

@@ -349,12 +357,12 @@ mkGCtx tyAgg (RootFlds flds) insCtxMap =
colTys = Set.toList $ Set.fromList $ map pgiType $
lefts $ Map.elems fldInfos
mkMutRoot =
mkHsraObjTyInfo (Just "mutation root") (G.NamedType "mutation_root") Set.empty .
mkHsraObjTyInfo (Just "mutation root") mutationRootTy Set.empty .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move out the descriptions also, so that can be reused?

@@ -152,11 +153,11 @@ mergeMutRoot a b =

mkNewEmptyMutRoot :: VT.ObjTyInfo
mkNewEmptyMutRoot = VT.ObjTyInfo (Just "mutation root")
Copy link
Member

@ecthiender ecthiender Mar 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse query/mutation descriptions ?

@@ -31,6 +31,7 @@ buildTx userInfo gCtx sqlCtx fld = do
, orderByCtx
, insCtxMap
, sqlCtx
, queryRootResolver
) $ case opCxt of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change this code to be more readable? the last argument to run convert, the case matching can be separate?
there is also a typo in opCxt. it should be opCtx.

Resolve Conflicts:
	server/src-lib/Hasura/GraphQL/Resolve/Insert.hs
	server/src-lib/Hasura/GraphQL/Resolve/Introspect.hs
	server/src-lib/Hasura/GraphQL/Resolve/Mutation.hs
	server/src-lib/Hasura/RQL/DML/Mutation.hs
	server/src-lib/Hasura/RQL/DML/Returning.hs
	server/src-lib/Hasura/RQL/DML/Select.hs
@netlify
Copy link

netlify bot commented Mar 20, 2019

Deploy preview for hasura-docs ready!

Built with commit 76ac0c4

https://deploy-preview-1759--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit 5f50a4f deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-5f50a4f

Copy link
Member

@ecthiender ecthiender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Resolve Conflicts:
	server/src-lib/Hasura/GraphQL/Resolve/Insert.hs
	server/src-lib/Hasura/GraphQL/Schema.hs
	server/src-lib/Hasura/RQL/DML/Mutation.hs
@hasura-bot
Copy link
Contributor

Review app for commit 08e465f deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-08e465f

Copy link

@rikinsk-zz rikinsk-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unqualified query fields in examples. We can add a separate example for the query in mutation use case later on.

rikinsk-zz
rikinsk-zz previously approved these changes Mar 25, 2019
Copy link

@rikinsk-zz rikinsk-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs LGTM

@hasura-bot
Copy link
Contributor

Review app for commit a1370f6 deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-a1370f6

Resolve Conflicts:
	server/src-lib/Hasura/GraphQL/Context.hs
	server/src-lib/Hasura/GraphQL/Resolve.hs
	server/src-lib/Hasura/GraphQL/Resolve/Context.hs
	server/src-lib/Hasura/GraphQL/Resolve/Mutation.hs
	server/src-lib/Hasura/GraphQL/Resolve/Select.hs
…graphql-engine into issue-1583-query-mut-resp-new
@hasura-bot
Copy link
Contributor

Review app for commit d91591c deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-d91591c

@dsandip dsandip added this to the release-candidates milestone Apr 15, 2019
Resolve Conflicts:
	docs/graphql/manual/mutations/delete.rst
	server/src-lib/Hasura/GraphQL/Explain.hs
	server/src-lib/Hasura/GraphQL/Resolve.hs
	server/src-lib/Hasura/GraphQL/Resolve/Context.hs
	server/src-lib/Hasura/GraphQL/Resolve/Insert.hs
	server/src-lib/Hasura/GraphQL/Resolve/Mutation.hs
	server/src-lib/Hasura/GraphQL/Resolve/Select.hs
	server/src-lib/Hasura/GraphQL/Schema.hs
	server/src-lib/Hasura/RQL/DML/Returning.hs
	server/src-lib/Hasura/RQL/DML/Select.hs
	server/src-lib/Hasura/RQL/DML/Select/Internal.hs
@hasura-bot
Copy link
Contributor

Review app for commit 7c84b7c deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-7c84b7c

Resolve Conflicts:
	server/src-lib/Hasura/RQL/DML/Select/Internal.hs
	server/src-lib/Hasura/RQL/Types/Error.hs
@hasura-bot
Copy link
Contributor

Review app for commit 76ac0c4 deployed to Heroku: https://hge-ci-pull-1759.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1759-76ac0c40

@CLAassistant
Copy link

CLAassistant commented Sep 17, 2019

CLA assistant check
All committers have signed the CLA.

@tirumaraiselvan tirumaraiselvan removed this from the release-candidates milestone Mar 13, 2020
@Stefmore02
Copy link
Contributor

Closing this PR due to merge conflicts.

@Stefmore02 Stefmore02 closed this Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/docs Related to docs c/server Related to server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add query root in mutation fields
9 participants