Skip to content

Commit 49b75c8

Browse files
committed
[auth][m] - add data field back but remove where clause
1 parent d8d749c commit 49b75c8

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

docker-compose.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ services:
2121
HASURA_GRAPHQL_DEV_MODE: 'true'
2222
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
2323
## uncomment next line to set an admin secret
24-
## HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
24+
##HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
25+
## uncomment next line to set an role that will be used for anauthenticated calls
26+
##HASURA_GRAPHQL_UNAUTHORIZED_ROLE: "anon"
2527
db:
2628
image: postgres
2729
ports:

routes/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ async function getGraphQLTableSchema(resource_id) {
2727
}
2828
`
2929
// return request(`${process.env.HASURA_URL}/v1/graphql`, queryForSchema)
30-
const graphQLClient = new GraphQLClient(`${process.env.HASURA_URL}/v1/graphql`, {
31-
headers: {
32-
'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET,
33-
},
34-
})
30+
const graphQLClient = new GraphQLClient(
31+
`${process.env.HASURA_URL}/v1/graphql`,
32+
{
33+
headers: {
34+
'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET,
35+
},
36+
}
37+
)
3538
try {
3639
const schemaPrep = await graphQLClient.request(queryForSchema)
3740
// console.log(JSON.stringify(schemaPrep, null, 2)) // TODO erase log
@@ -92,13 +95,17 @@ router.get(`/${APP_VERSION}/datastore_search`, async function (req, res, next) {
9295
// query for schema -> this should be already in Frictionless format
9396
// const schema = await queryForSchema()
9497
const schema = await getGraphQLTableSchema(table)
98+
console.log(schema)
99+
const data = await queryForData(schema, req.query)
100+
console.log(data.errors)
95101
/*TODO*/
96102
/* Auth handling ... maybe JWT? */
97103
// Mandatory GET parameters check
98104

99105
// response
100106
res.send({
101107
schema: beautifyGQLSchema(schema),
108+
data,
102109
})
103110
} catch (e) {
104111
console.error(e)

routes/queryGraphQL.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { request, gql, GraphQLClient } = require('graphql-request')
1+
const { request, gql } = require('graphql-request')
22
const { app } = require('../app')
33

44
async function queryForData(schema, params) {
@@ -28,8 +28,9 @@ async function queryForData(schema, params) {
2828
}
2929
// console.log("Variables = "+ JSON.stringify(variables))
3030
const query = buildParametrableQuery(schema, queryParams)
31-
return request(process.env.HASURA_URL + '/v1/graphql', query, variables)
32-
.then((resp) => resp[params.resource_id])
31+
return request(process.env.HASURA_URL + '/v1/graphql', query, variables).then(
32+
(resp) => resp[params.resource_id]
33+
)
3334
}
3435

3536
/**
@@ -77,9 +78,6 @@ function buildParametrableQuery(schema, params) {
7778
return gql`query ${params.resource_id}_query (${variablesDeclaration}) {
7879
${params.resource_id}(
7980
limit: ${limit},
80-
where: {
81-
${whereFields.join(' ')}
82-
},
8381
offset: $offset,
8482
${extraFields}
8583
) {

0 commit comments

Comments
 (0)