hasura / ask-me-anything Goto Github PK
View Code? Open in Web Editor NEWThis is a repository for the AMA live video sessions.
This is a repository for the AMA live video sessions.
UUID stands for a universally unique identifier. Another term which is common for a UUID, is the GUID, or globally unique identifier, which is the common term Microsoft created for their UUIDs. Just know, that a GUID is a UUID, it's just company naming convention vs the standard industry naming convention.
UUIDs are standardized by the Open Software Foundation (OSF) as part of the Distributed Computer Environment (DCE). Specifically UUID are designed and used from an USO/IEC spec, which if you'd like to know more about the standards they're based on check out the Wikipedia page @ https://en.wikipedia.org/wiki/Universally_unique_identifier
The canonical textual representation, the 16 octets of a UUID are represented as 32 hexadecimal (base-016) digits. They're displayed across five groups separated by hyphens in 8-4-4-4-12 format. Even though there are 32 hexadecimal digits, this makes a total of 36 characters for format display. If storing as a string for example, the string needs to be able to hold 36 characters.
The first key use case for a UUID is to have something generate the UUID to use it as a completely unique value for use with a subset of related data. UUIDs are prefect for primary keys in a database, or simply any type of key to ensure uniqueness across a system.
UUIDs can be generated from many different origin points too without any significant concern for collision (i.e. duplicate UUIDs). For example, the database itself has database functions that enable the generation of a UUID at time of a data row's insertion, as a default value. This means a client inserting data wouldn't need to generate that UUID. However this can be flipped over to the client side as a responsibility and the client side development stack (i.e. like Go UUID generation) can generate the UUID. Which then enables the creation of a primary key entity being created with a UUID as the primary key, that can then be used to create what would be foreign key items and so on down the chain of a relationship. Then once all of these are created on the client side they can all be inserted in a batch, and even if ordered appropriately can be made transactional to ensure the integrity of the data.
Short IDs like URL safe shortened identifiers of some sort or something like hash identifiers.
If I have a jsonb field/column, but the value is, in some cases, a string, e.g. "abc123". I'd like to be able to query that value with something like the "LIKE" query on it. From what I can find, this is supported by Postgres and requires you to basically cast the field/value as "text" and then you can do the "LIKE" query, see https://stackoverflow.com/a/57562423/1374827 for an example. For cases where the field value was not a string (e.g. it's a float, or array, or object), I wouldn't really care how Hasura behaved, although I would assume it would make sense that it would still cast the value as text and then attempt to perform a "LIKE" query on the result. The overall outcome that would be great is if like and _ilike were available as new options for the where parameter for jsonb fields/columns, i.e. if they were added to jsonb_comparison_exp. Will this be available in the future?
Table of contents
List of PostgreSQL types supported by the Hasura GraphQL engine with their equivalent Hasura types:
Name | Aliases | Description | Hasura Type |
---|---|---|---|
bigint | int8 | signed eight-byte integer | String |
bigserial | serial8 | autoincrementing eight-byte integer | String |
bit [ (n) ] | fixed-length bit string | Implicit | |
bit varying [ (n) ] | varbit [ (n) ] | variable-length bit string | Implicit |
boolean | bool | logical Boolean (true/false) | Bool |
box | rectangular box on a plane | Implicit | |
bytea | binary data (“byte array”) | Implicit | |
character [ (n) ] | char [ (n) ] | fixed-length character string | Char |
character varying [ (n) ] | varchar [ (n) ] | variable-length character string | String |
cidr | IPv4 or IPv6 network address | Implicit | |
circle | circle on a plane | Implicit | |
date | calendar date (year, month, day) | Date | |
double precision | float8 | double precision floating-point number (8 bytes) | Float |
inet | IPv4 or IPv6 host address | Implicit | |
integer | int, int4 | signed four-byte integer | Int |
interval [ fields ] [ (p) ] | time span | Implicit | |
json | textual JSON data | JSON | |
jsonb | binary JSON data, decomposed | JSONB | |
line | infinite line on a plane | Implicit | |
lseg | line segment on a plane | Implicit | |
ltree | labels of data stored in a hierarchical tree-like structure | Implicit | |
geometry | PostGIS Geometry type | Geometry | |
geography | PostGIS Geography type | Geography | |
macaddr | MAC (Media Access Control) address | Implicit | |
macaddr8 | MAC (Media Access Control) address (EUI-64 format) | Implicit | |
money | currency amount | Implicit | |
numeric [ (p, s) ] | decimal [ (p, s) ] | exact numeric of selectable precision | Numeric |
path | geometric path on a plane | Implicit | |
pg_lsn | PostgreSQL Log Sequence Number | Implicit | |
point | geometric point on a plane | Implicit | |
polygon | closed geometric path on a plane | Implicit | |
real | float4 | single precision floating-point number (4 bytes) | Float |
smallint | int2 | signed two-byte integer | Int |
smallserial | serial2 | autoincrementing two-byte integer | Int |
serial | serial4 | autoincrementing four-byte integer | Int |
text | variable-length character string | String | |
time [ (p) ] [ without time zone ] | time of day (no time zone) | Implicit | |
time [ (p) ] with time zone | timetz | time of day, including time zone | Timetz |
timestamp [ (p) ] [ without time zone ] | date and time (no time zone) | Implicit | |
timestamp [ (p) ] with time zone | timestamptz | date and time, including time zone | Timestamptz |
tsquery | text search query | Implicit | |
tsvector | text search document | Implicit | |
txid_snapshot | user-level transaction ID snapshot | Implicit | |
uuid | universally unique identifier | Implicit | |
xml | XML data | Implicit |
GraphQL custom scalar type with name float8.
E.g.
objects: [ { float_col: 0.8 } ]
Note
To avoid loss of data when retrieving IEEE 754 style data from the database,
please refer to the GraphQL engine server config reference for instructions on setting
the extra_float_digits
parameter, which has a bad default value in
PostgreSQL 11 and older.
GraphQL custom scalar type with name numeric.
E.g.
objects: [ { numeric_col: 0.00000008 } ]
GraphQL default Scalar with name Boolean. The Boolean scalar type represents true
or false
.
E.g.
objects: [ { is_published: true } ]
GraphQL custom scalar with name character. It is a String
with single character.
E.g.
objects: [ { char_column: "a" } ]
GraphQL default scalar with name String. The String scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
E.g.
objects: [ { name: "Raven" } ]
GraphQL custom scalar with name date. Date (no time of day). Allowed values are yyyy-mm-dd.
E.g.
objects: [ { date: "1996-03-15" } ]
GraphQL custom scalar type with name timetz. Time of day only, with time zone. Allowed values should be of ISO8601 format (e.g. 17:30:15Z, 17:30:15+05:30, 17:30:15.234890+05:30).
E.g.
objects: [ { time: "17:30:15+05:30" } ]
GraphQL custom scalar type with name timestamptz. Both date and time, with time zone. Allowed values should be of ISO8601 format (e.g. 2016-07-20T17:30:15Z, 2016-07-20T17:30:15+05:30, 2016-07-20T17:30:15.234890+05:30).
E.g.
objects: [ { timestamptz_col: "2016-07-20T17:30:15+05:30" } ]
GraphQL custom scalar type with name json. It is a stringified json value.
E.g.
objects: [ { json_col: "{ \"name\": \"raven\" }" } ]
GraphQL custom scalar type with name jsonb. Value should be given through a variable of type jsonb.
E.g.
mutation insert_test($value : jsonb) { insert_test( objects: [ { jsonb_col: $value } ] ) { affected_rows returning{ jsonb_col } } }
variables:
{ "value": { "name": "raven" } }
GraphQL custom scalar type geometry
is generated for a GEOMETRY
column
on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.
E.g.
mutation insertGeometry($point: geometry!) { insert_test( objects: [{ geometry_col: $point }] ) { affected_rows returning { geometry_col } } }
variables:
{ "point": { "type": "Point", "coordinates": [0, 0] } }
GraphQL custom scalar type geography
is generated for a GEOGRAPHY
column
on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.
E.g.
mutation insertGeography($point: geography!) { insert_test( objects: [{ geography_col: $point }] ) { affected_rows returning { geography_col } } }
variables:
{ "point": { "type": "Point", "coordinates": [0, 0] } }
All Implicit
types in the above table are implicitly supported by the GraphQL engine. You have to
provide the value as a String.
E.g. For time without time zone type
In ISO 8601 format
objects: [ { time_col: "04:05:06.789" } ]
E.g. For macaddr type
objects: [ { macaddr_col: "08:00:2b:01:02:03" } ]
Note
You can learn more about PostgreSQL data types here.
The quick list to figure out the performance of queries is to determine what is being executed from the SQL call.
Will elaborate soon on an upcoming AMA session.
when creating my tables in the hasura console i forgot to make the id auto incremental for all the tables i used and after that when i tried to change them all to that there wasn't any easy way available i could find so i had to create alter statements for all the tables on the raw sql to do my tasks but since that is a lot of work can i ask if there is a better way already made.
How to add increment primary key in an existing PostgreSQL table?
Get a list of available benchmarks and prospective benchmarks that are or will be available publicly.
Subsequent related question(s) and additional information:
Is it a good practice to pass the 'x-hasura-role' header per GraphQL query?
So almost always setting a role to a query, like setting the role public on queries that are related to public data / profiles, setting all queries / mutations related to the current user to the user role, e.g. editing the profile, viewing it's own personal information, e.g. email, etc.
We're also switching all roles to admin in case an admin is logged in, so admin's can change and do whatever they want. Any thoughts? This is something we've done on the fly, figured out ourselves to do using Apollo Client's context property in queries / mutation, but never seen it being done this way anywhere else so wondering how other people deal with this.
Table of contents
List of PostgreSQL types supported by the Hasura GraphQL engine with their equivalent Hasura types:
Name | Aliases | Description | Hasura Type |
---|---|---|---|
bigint | int8 | signed eight-byte integer | String |
bigserial | serial8 | autoincrementing eight-byte integer | String |
bit [ (n) ] | fixed-length bit string | Implicit | |
bit varying [ (n) ] | varbit [ (n) ] | variable-length bit string | Implicit |
boolean | bool | logical Boolean (true/false) | Bool |
box | rectangular box on a plane | Implicit | |
bytea | binary data (“byte array”) | Implicit | |
character [ (n) ] | char [ (n) ] | fixed-length character string | Char |
character varying [ (n) ] | varchar [ (n) ] | variable-length character string | String |
cidr | IPv4 or IPv6 network address | Implicit | |
circle | circle on a plane | Implicit | |
date | calendar date (year, month, day) | Date | |
double precision | float8 | double precision floating-point number (8 bytes) | Float |
inet | IPv4 or IPv6 host address | Implicit | |
integer | int, int4 | signed four-byte integer | Int |
interval [ fields ] [ (p) ] | time span | Implicit | |
json | textual JSON data | JSON | |
jsonb | binary JSON data, decomposed | JSONB | |
line | infinite line on a plane | Implicit | |
lseg | line segment on a plane | Implicit | |
ltree | labels of data stored in a hierarchical tree-like structure | Implicit | |
geometry | PostGIS Geometry type | Geometry | |
geography | PostGIS Geography type | Geography | |
macaddr | MAC (Media Access Control) address | Implicit | |
macaddr8 | MAC (Media Access Control) address (EUI-64 format) | Implicit | |
money | currency amount | Implicit | |
numeric [ (p, s) ] | decimal [ (p, s) ] | exact numeric of selectable precision | Numeric |
path | geometric path on a plane | Implicit | |
pg_lsn | PostgreSQL Log Sequence Number | Implicit | |
point | geometric point on a plane | Implicit | |
polygon | closed geometric path on a plane | Implicit | |
real | float4 | single precision floating-point number (4 bytes) | Float |
smallint | int2 | signed two-byte integer | Int |
smallserial | serial2 | autoincrementing two-byte integer | Int |
serial | serial4 | autoincrementing four-byte integer | Int |
text | variable-length character string | String | |
time [ (p) ] [ without time zone ] | time of day (no time zone) | Implicit | |
time [ (p) ] with time zone | timetz | time of day, including time zone | Timetz |
timestamp [ (p) ] [ without time zone ] | date and time (no time zone) | Implicit | |
timestamp [ (p) ] with time zone | timestamptz | date and time, including time zone | Timestamptz |
tsquery | text search query | Implicit | |
tsvector | text search document | Implicit | |
txid_snapshot | user-level transaction ID snapshot | Implicit | |
uuid | universally unique identifier | Implicit | |
xml | XML data | Implicit |
GraphQL custom scalar type with name float8.
E.g.
objects: [ { float_col: 0.8 } ]
Note
To avoid loss of data when retrieving IEEE 754 style data from the database,
please refer to the GraphQL engine server config reference for instructions on setting
the extra_float_digits
parameter, which has a bad default value in
PostgreSQL 11 and older.
GraphQL custom scalar type with name numeric.
E.g.
objects: [ { numeric_col: 0.00000008 } ]
GraphQL default Scalar with name Boolean. The Boolean scalar type represents true
or false
.
E.g.
objects: [ { is_published: true } ]
GraphQL custom scalar with name character. It is a String
with single character.
E.g.
objects: [ { char_column: "a" } ]
GraphQL default scalar with name String. The String scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
E.g.
objects: [ { name: "Raven" } ]
GraphQL custom scalar with name date. Date (no time of day). Allowed values are yyyy-mm-dd.
E.g.
objects: [ { date: "1996-03-15" } ]
GraphQL custom scalar type with name timetz. Time of day only, with time zone. Allowed values should be of ISO8601 format (e.g. 17:30:15Z, 17:30:15+05:30, 17:30:15.234890+05:30).
E.g.
objects: [ { time: "17:30:15+05:30" } ]
GraphQL custom scalar type with name timestamptz. Both date and time, with time zone. Allowed values should be of ISO8601 format (e.g. 2016-07-20T17:30:15Z, 2016-07-20T17:30:15+05:30, 2016-07-20T17:30:15.234890+05:30).
E.g.
objects: [ { timestamptz_col: "2016-07-20T17:30:15+05:30" } ]
GraphQL custom scalar type with name json. It is a stringified json value.
E.g.
objects: [ { json_col: "{ \"name\": \"raven\" }" } ]
GraphQL custom scalar type with name jsonb. Value should be given through a variable of type jsonb.
E.g.
mutation insert_test($value : jsonb) { insert_test( objects: [ { jsonb_col: $value } ] ) { affected_rows returning{ jsonb_col } } }
variables:
{ "value": { "name": "raven" } }
GraphQL custom scalar type geometry
is generated for a GEOMETRY
column
on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.
E.g.
mutation insertGeometry($point: geometry!) { insert_test( objects: [{ geometry_col: $point }] ) { affected_rows returning { geometry_col } } }
variables:
{ "point": { "type": "Point", "coordinates": [0, 0] } }
GraphQL custom scalar type geography
is generated for a GEOGRAPHY
column
on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.
E.g.
mutation insertGeography($point: geography!) { insert_test( objects: [{ geography_col: $point }] ) { affected_rows returning { geography_col } } }
variables:
{ "point": { "type": "Point", "coordinates": [0, 0] } }
All Implicit
types in the above table are implicitly supported by the GraphQL engine. You have to
provide the value as a String.
E.g. For time without time zone type
In ISO 8601 format
objects: [ { time_col: "04:05:06.789" } ]
E.g. For macaddr type
objects: [ { macaddr_col: "08:00:2b:01:02:03" } ]
Note
You can learn more about PostgreSQL data types here.
Per @coco98 "It’s slotted right after we wrap up 2.0 stable release. :) Camel, Pascal and snake casing options."
I have opinions about all sorts of things, and that being the case, I have multiple answers for this question!
Hello,
I have a problem with migrations using the latest version of hasura and hasura cli using config v3.
I am trying to migrate from google cloudrun:
Hasura v2.1.1
PostgresSQL v13.4
https://hasura-clone-yyljssc5aq-ey.a.run.app/console = works fine
https://hasura-clone-yyljssc5aq-ey.a.run.app/healthz = results: 404 error
To my local environment:
Hasura cli v2.1.1
Hasura v2.1.1
PostgresSQL v13.4
http://localhost:8080/console = works fine
http://localhost:8080/healthz = results: OK
I’m following the official documentation steps on my local environment:
install hasura-cli locally via npm inside a folder: $ npm install --save-dev @aaronhayes/hasura-cli@latest
$ npx hasura version (results v2.1.1)
$ npx hasura init myproject --endpoint https://hasura-clone-yyljssc5aq-ey.a.run.app --admin-secret
$ cd myproject
npx hasura migrate create "init" --from-server
I get this errors:
ERRO connecting to graphql-engine server failedINFO possible reasons:
INFO 1) Provided root endpoint of graphql-engine server is wrong. Verify endpoint key in config.yaml or/and value of --endpoint flag
INFO 2) Endpoint should NOT be your GraphQL API, ie endpoint is NOT https://hasura-cloud-app.io/v1/graphql it should be: https://hasura-cloud-app.io
INFO 3) Server might be unhealthy and is not running/accepting API requests
INFO 4) Admin secret is not correct/set
INFO time="2021-12-22T02:23:08+02:00" level=fatal msg="request failed: url: https://hasura-clone-yyljssc5aq-ey.a.run.app/healthz status code: 404 status: 404 Not Found"
So if I acces https://hasura-clone-yyljssc5aq-ey.a.run.app/healthz = I get 404 error ☹
Is this a problem with hasura installation on my google cloudrun or is this a problem with hasura cli because of postgres version v13.4 ?
This is urgent for me and I really appreciate any help I can get !
Thanks
In a multi-tenant app one tenant can create new entities like leads, orders, etc. to model business activity via an app UI and could the underlying tables be created on the fly in the underlying Postgres database?
Per @scriptonist "CLI is aware of the expected metadata structure and parses the raw metadata (from the server) to determine the files to edit."
Yes. However there needs to be a metadata database, which can be connected using the environment variable HASURA_GRAPHQL_METADATA_DATABASE_URL. Any other databases can then be connected using what configuration in regards to read, write, or read-only.
Good posts on the topic.
I kind of get the idea of event, action, and remote schema.
how about just put everything in hasura and I get a single true table?
It would be really lovely to see 20 mins hack to get everything setup and running
ODBC Format Docs: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms722656(v=vs.85)
Important notes:
An app has the ability to disable users. When a user is disabled, I update the JWT claims to contain "X-Hasura-Enabled": false. However it seems difficult to craft permissions expressions to accept access if this claim either doesn't exist, or is set to true, and deny otherwise. I could change the X-Hasura-Role claim instead and not touch the permissions logic, but that seems more like a hack than a proper solution, as the claimed role won't match the actual role (the user's role hasn't changed, she's just disabled).
IMO it would be easier to update the user table instead of the token. and use the _exists in the permission https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#using-unrelated-tables-views (per leoalves)
I originally wanted to apply this to my currently used Hasura DB (hosted on Heroku), but decided to test it out on a fresh project first. I was unable to both deploy locally and deploy on Heroku. I'm a total rookie considering the backend, but I don't want to use Firebase/Auth0, as this solution seems perfect for most use cases. If I could accomplish this, I could get happily back to Nuxt and VueJS and not worry about the database stuff for a while :)
Both of my journeys went south, I bring local deploy as an example:
Deploy locally
Clone the repo (success)
git clone https://github.com/hasura/graphql-engine
Change directory (success)
cd graphql-engine/community/boilerplates/auth-webhooks/passport-js
Install NPM dependencies (failed - Bcrypt gave 404)
npm install
#Commands I used to perhaps succeed (introduced vulnerabilities which I haven't yet fixed)
npm cache clean -f
npm install bcrypt --save
Set DATABASE_URL env (failed - Unsure where I can find the .env file)
export DATABASE_URL=postgres://:@:/<database_name>
Apply migrations. Note: this step creates a "users" table in the database (failed, don't know what knex is or how to use it)
knex migrate:latest
Then simply start your app (failed - Didn't even bother to try at this point)
npm start
I believe users are a fundamental and one of the toughest part to do right The documentation flies waay over entry level guys like me. So please, help us out or Auth0 will consume us with all their available tutorials..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.