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 1 commit
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
Next Next commit
fix introspection fails for non admin role, fix #340
  • Loading branch information
rakeshkky committed Aug 31, 2018
commit f26db0d3b4d5d0e1cb7d0a2f7eaf513a7fb45946
9 changes: 6 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,13 @@ type table_mutation_response {
-}
mkMutRespObj
:: QualifiedTable
-> Maybe () -- sel perm
Copy link
Member

Choose a reason for hiding this comment

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

Use a Bool

-> ObjTyInfo
mkMutRespObj tn =
mkMutRespObj tn selM =
mkObjTyInfo (Just objDesc) (mkMutRespTy tn) $ mapFromL _fiName
[affectedRowsFld, returningFld]
$ catMaybes [ Just affectedRowsFld
, const returningFld <$> selM
]
where
objDesc = G.Description $
"response of any mutation on the table " <>> tn
Expand Down Expand Up @@ -896,7 +899,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 $ void 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
}
}
}
}
}
}
}
}