Skip to content

Commit 3367123

Browse files
authored
Merge pull request #32 from luccasmmg/master
[resource_search][m] - fix timeout when hasura instance has auth
2 parents ff69a38 + 49b75c8 commit 3367123

5 files changed

Lines changed: 59 additions & 23 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:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"express": "~4.16.1",
1818
"express-http-proxy": "^1.6.2",
1919
"graphql": "^15.3.0",
20-
"graphql-request": "^3.1.0",
20+
"graphql-request": "^5.1.0",
2121
"http-errors": "~1.6.3",
2222
"morgan": "~1.9.1",
2323
"node-fetch": "^2.6.1",

routes/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var router = express.Router()
33
const { Readable, finished } = require('stream')
44
const { once } = require('events')
55

6-
const { request, gql } = require('graphql-request')
6+
const { request, gql, GraphQLClient } = require('graphql-request')
77

88
const { queryForData } = require('./queryGraphQL')
99
const XLSX = require('xlsx')
@@ -27,11 +27,16 @@ async function getGraphQLTableSchema(resource_id) {
2727
}
2828
`
2929
// return request(`${process.env.HASURA_URL}/v1/graphql`, queryForSchema)
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+
)
3038
try {
31-
const schemaPrep = await request(
32-
`${process.env.HASURA_URL}/v1/graphql`,
33-
queryForSchema
34-
)
39+
const schemaPrep = await graphQLClient.request(queryForSchema)
3540
// console.log(JSON.stringify(schemaPrep, null, 2)) // TODO erase log
3641
schema = schemaPrep.__type
3742
} catch (e) {
@@ -90,16 +95,17 @@ router.get(`/${APP_VERSION}/datastore_search`, async function (req, res, next) {
9095
// query for schema -> this should be already in Frictionless format
9196
// const schema = await queryForSchema()
9297
const schema = await getGraphQLTableSchema(table)
93-
// query for data -> basically the call to queryGraphQL
98+
console.log(schema)
9499
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),
102-
data: data,
108+
data,
103109
})
104110
} catch (e) {
105111
console.error(e)

routes/queryGraphQL.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ function buildParametrableQuery(schema, params) {
7878
return gql`query ${params.resource_id}_query (${variablesDeclaration}) {
7979
${params.resource_id}(
8080
limit: ${limit},
81-
where: {
82-
${whereFields.join(' ')}
83-
},
8481
offset: $offset,
8582
${extraFields}
8683
) {

yarn.lock

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# yarn lockfile v1
33

44

5+
"@graphql-typed-document-node/core@^3.1.1":
6+
version "3.1.1"
7+
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052"
8+
integrity sha512-NQ17ii0rK1b34VZonlmT2QMJFI70m0TRwbknO/ihlbatXyaktDhN/98vBiUU6kNBPljqGqyIrl2T4nY2RpFANg==
9+
510
"@types/color-name@^1.1.1":
611
version "1.1.1"
712
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
@@ -337,12 +342,12 @@ crc-32@~1.2.0:
337342
exit-on-epipe "~1.0.1"
338343
printj "~1.1.0"
339344

340-
cross-fetch@^3.0.5:
341-
version "3.0.6"
342-
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c"
343-
integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==
345+
cross-fetch@^3.1.5:
346+
version "3.1.5"
347+
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
348+
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
344349
dependencies:
345-
node-fetch "2.6.1"
350+
node-fetch "2.6.7"
346351

347352
debug@2.6.9, debug@~2.6.9:
348353
version "2.6.9"
@@ -677,12 +682,13 @@ glob@7.1.6:
677682
once "^1.3.0"
678683
path-is-absolute "^1.0.0"
679684

680-
graphql-request@^3.1.0:
681-
version "3.1.0"
682-
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-3.1.0.tgz#c487488a1aa7b9a0f02335026b4ec897d645f9d4"
683-
integrity sha512-Flg2Bd4Ek9BDJ5qacZC/iYuiS3LroHxQTmlUnfqjo/6jKwowY25FVtoLTnssMCBrYspRYEYEIfF1GN8J3/o5JQ==
685+
graphql-request@^5.1.0:
686+
version "5.1.0"
687+
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-5.1.0.tgz#dbc8feee27d21b993cd5da2d3af67821827b240a"
688+
integrity sha512-0OeRVYigVwIiXhNmqnPDt+JhMzsjinxHE7TVy3Lm6jUzav0guVcL0lfSbi6jVTRAxcbwgyr6yrZioSHxf9gHzw==
684689
dependencies:
685-
cross-fetch "^3.0.5"
690+
"@graphql-typed-document-node/core" "^3.1.1"
691+
cross-fetch "^3.1.5"
686692
extract-files "^9.0.0"
687693
form-data "^3.0.0"
688694

@@ -1018,7 +1024,14 @@ negotiator@0.6.2:
10181024
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
10191025
integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==
10201026

1021-
node-fetch@2.6.1, node-fetch@^2.6.1:
1027+
node-fetch@2.6.7:
1028+
version "2.6.7"
1029+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
1030+
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
1031+
dependencies:
1032+
whatwg-url "^5.0.0"
1033+
1034+
node-fetch@^2.6.1:
10221035
version "2.6.1"
10231036
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
10241037
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
@@ -1443,6 +1456,11 @@ toidentifier@1.0.0:
14431456
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
14441457
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
14451458

1459+
tr46@~0.0.3:
1460+
version "0.0.3"
1461+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
1462+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
1463+
14461464
type-detect@^4.0.0, type-detect@^4.0.5:
14471465
version "4.0.8"
14481466
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
@@ -1476,6 +1494,19 @@ vary@^1, vary@~1.1.2:
14761494
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
14771495
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
14781496

1497+
webidl-conversions@^3.0.0:
1498+
version "3.0.1"
1499+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
1500+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
1501+
1502+
whatwg-url@^5.0.0:
1503+
version "5.0.0"
1504+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
1505+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
1506+
dependencies:
1507+
tr46 "~0.0.3"
1508+
webidl-conversions "^3.0.0"
1509+
14791510
which-module@^2.0.0:
14801511
version "2.0.0"
14811512
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

0 commit comments

Comments
 (0)