Skip to content

Commit

Permalink
generate a returning field in a mutation only when the select permiss…
Browse files Browse the repository at this point in the history
…ion is defined (fix #340) (#341)
  • Loading branch information
rakeshkky authored and 0x777 committed Sep 3, 2018
1 parent ea9b187 commit 10edb43
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/src-lib/Hasura/GraphQL/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,11 @@ type table_mutation_response {
-}
mkMutRespObj
:: QualifiedTable
-> Bool -- is sel perm defined
-> ObjTyInfo
mkMutRespObj tn =
mkMutRespObj tn sel =
mkObjTyInfo (Just objDesc) (mkMutRespTy tn) $ mapFromL _fiName
[affectedRowsFld, returningFld]
$ affectedRowsFld : bool [] [returningFld] sel
where
objDesc = G.Description $
"response of any mutation on the table " <>> tn
Expand Down Expand Up @@ -896,7 +897,7 @@ mkGCtxRole' tn insColsM selFldsM updColsM delPermM pkeyCols constraints =
-- mut resp obj
mutRespObjM =
if isJust insColsM || isJust updColsM || isJust delPermM
then Just $ mkMutRespObj tn
then Just $ mkMutRespObj tn $ isJust selFldsM
else Nothing

-- table obj
Expand Down
1 change: 1 addition & 0 deletions server/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ querySpecFiles =
gqlSpecFiles :: [FilePath]
gqlSpecFiles =
[ "introspection.yaml"
, "introspection_user_role.yaml"
, "insert_mutation/author.yaml"
, "simple_select_query_author.yaml"
, "select_query_author_by_pkey.yaml"
Expand Down
106 changes: 106 additions & 0 deletions server/test/testcases/introspection_user_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
description: GraphQL introspection query as user role
url: /v1alpha1/graphql
status: 200
headers:
X-Hasura-Role: user
query:
query: |
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
}
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}

0 comments on commit 10edb43

Please sign in to comment.