Skip to content

Commit

Permalink
fix(console): add houdinigraphql
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Jan 22, 2024
1 parent be43e53 commit 1883f66
Show file tree
Hide file tree
Showing 17 changed files with 3,154 additions and 7 deletions.
3 changes: 3 additions & 0 deletions apps/console/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ coverage/*
# Project files #
#############################
src/i18n
dev-dist
schema.graphql
$houdini
11 changes: 11 additions & 0 deletions apps/console/.graphqlrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
projects:
default:
schema:
- ./schema.graphql
- ./$houdini/graphql/schema.graphql
# - ../../nhost/tailcall/jsonplaceholder.graphql
# - ../../nhost/tailcall/.tailcallrc.graphql
documents:
- '**/*.gql'
- '**/*.svelte'
- ./$houdini/graphql/documents.gql
133 changes: 133 additions & 0 deletions apps/console/houdini.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/// <references types="houdini-svelte">
const defaultMarshall = {
unmarshal(val) {
return val;
},

marshal(val) {
return val;
}
};

/** @type {import('houdini').ConfigFile} */
const config = {
watchSchema: {
url: (env) => env.PUBLIC_GRAPHQL_ENDPOINT,
interval: 0, // only pull the schema when you first run `turbo dev`
// HINT: we need to generate scheam for highest role level that app support.
headers: {
'X-Hasura-Admin-Secret': (env) => env.HASURA_GRAPHQL_ADMIN_SECRET,
'x-hasura-allowed-roles': 'user manager',
'x-hasura-role': 'manager'
}
},
plugins: {
// 'houdini-plugin-svelte-global-stores': {
// generate: 'all'
// },
'houdini-svelte': {
client: './src/lib/graphql/client'
}
},
scalars: {
// ref: https://www.houdinigraphql.com/api/config#custom-scalars
DateTime: {
// the corresponding typescript type
type: 'Date',
// turn the api's response into that type
unmarshal(val) {
return new Date(val);
},
// turn the value into something the API can use
marshal(date) {
// return date.getTime();
return date?.toISOString();
}
},

Decimal: {
type: 'number',
unmarshal(val) {
return new Number(val);
},
marshal(number) {
return number.toString();
}
},
smallint: {
type: 'number',
unmarshal(val) {
return new Number(val);
},
marshal(number) {
return number.toString();
}
},
URL: {
type: 'URL',
unmarshal(val) {
return new URL(val);
},
marshal(url) {
return url.toString();
}
},
hstore: {
type: 'string',
unmarshal(val) {
return Object.entries(val)
.map(([k, v]) => `"${k}" => "${v}"`)
.join(', ');
},
marshal(val) {
return val;
}
},
// FIXME: https://github.com/hasura/graphql-engine/issues/348
// hstore: {
// type: 'Map',
// unmarshal(val) {
// console.log('in hstore unmarshal', val, typeof val);
// return new Map(Object.entries(val));
// },
// marshal(val) {
// console.log('in hstore marshal', val, typeof val);
// return Object.entries(JSON.parse(val))
// .map(([k, v]) => `"${k}" => "${v}"`)
// .join(', ');
// }
// },
uuid: {
type: 'string',
...defaultMarshall
},
jsonb: {
type: 'object',
...defaultMarshall
},
timestamp: {
type: 'Date',
unmarshal(val) {
return new Date(val);
},
marshal(date) {
return date?.toISOString();
}
},
timestamptz: {
type: 'Date',
unmarshal(val) {
// TODO: https://www.tutorialspoint.com/how-to-convert-utc-date-time-into-local-date-time-using-javascript
// const server = new Date(val);
// const offset = server.getTimezoneOffset();
// return new Date(server.getTime() + offset * 60000);
return new Date(val);
},
marshal(date) {
return date?.toISOString();
}
}
}
};

export default config;
1 change: 1 addition & 0 deletions apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"eslint-config-prettier": "9.1.0",
"eslint-plugin-svelte": "2.35.1",
"formsnap": "0.4.2",
"graphql-ws": "5.14.3",
"houdini": "1.2.36",
"houdini-svelte": "1.2.36",
"layerchart": "0.27.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/console/project.inlang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"auth_labels_reset_problem": "Reset Password Problem",
"auth_labels_send_peset_email": "Send Password Reset Email",
"auth_messages_aaa": "Send Password Reset Email",
"auth_forms_first_organization_label": "Organization",
"auth_forms_first_organization_placeholder": "Organization",
"auth_forms_first_name_label": "First Name",
"auth_forms_first_name_placeholder": "First Name",
"auth_forms_last_name_label": "Last Name",
Expand Down
Loading

0 comments on commit 1883f66

Please sign in to comment.