deepcase hasura
api
import { HasuraApi } from '@deepcase/hasura/api';
const api = new HasuraApi({
path: 'hasura.domain.com',
ssl: true,
secret: 'adminsecretkey'
});
sql template literal for ide highlighting
import { sql } from '@deepcase/hasura/sql';
await api.sql(sql`SELECT * FROM mytable`);
hasura api reference
await api.query({
type: 'track_table',
args: {
schema: 'public',
name: 'mytable',
}
});
client
import { generateApolloClient } from '@deepcase/hasura/client';
import gql from 'graphql-tag';
const client = generateApolloClient({
ws: true,
secret: 'adminSecretForRoot',
token: 'tokenFromCookiesOrLocalStorage',
ssl: true;
path: 'hasura.domain.com/path',
headers: {},
initialStore: {},
relative: false,
});
client.query({ query: gql`{ links { id }}` }).then(result => console.log(result))
If you need to specify an absolute path as protocol://domain.zone/path
to hasura, you must pass these two options: path
and ssl
const client = generateApolloClient({
ssl: true;
path: 'hasura.domain.com/path',
});
If you need to specify relative path as /path
to hasura, you must enable the relative mode with the relative
option. In this case, the ssl
option is ignored in http
client, but used in ws
. This can be useful when your build is with some proxy.
const client = generateApolloClient({
relative: true,
path: 'hasura.domain.com/path',
});
You can also specify relative not locally in your code, but using an ENV variable DEEP_FOUNDATION_HASURA_RELATIVE
or NEXT_PUBLIC_DEEP_FOUNDATION_HASURA_RELATIVE
.
export DEEP_FOUNDATION_HASURA_RELATIVE = 1;
OR
export NEXT_PUBLIC_DEEP_FOUNDATION_HASURA_RELATIVE = 1;