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

generate mutation returning types only if permissions are defined (fix #340) #341

Merged
merged 2 commits into from
Sep 3, 2018
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
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
}
}
}
}
}
}
}
}