Skip to content

Commit f67337d

Browse files
docs: update hasura with examples of graphQL useage and postgres, and… (#148)
… missing dns config details from custom deployments ## Summary by Sourcery Document Hasura usage with GraphQL and PostgreSQL, and add missing DNS configuration details for custom deployments. Enhancements: - Add missing DNS configuration details for custom deployments, including obtaining the application's hostname, accessing DNS settings, configuring DNS records, setting TTL, verifying DNS propagation, and SSL/TLS configuration. Documentation: - Document Hasura database interaction through GraphQL API and direct PostgreSQL connection. - Add usage examples for GraphQL and PostgreSQL. - Document authentication setup for both GraphQL and PostgreSQL. Co-authored-by: saeeddawod <saeed.dawod@gmail.com>
1 parent b97eae3 commit f67337d

File tree

2 files changed

+222
-3
lines changed

2 files changed

+222
-3
lines changed

docs/using-platform/14_custom-deployment.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A Custom Deployment allows you to deploy your own Docker images, such as fronten
2525
- Environment variables (if required)
2626
- Custom domain information (if applicable)
2727
5. Configure any additional settings as needed.
28-
6. Click on 'Confirm' and wait for the Custom Deployment to be in the Running status.
28+
6. Click on 'Confirm' and wait for the Custom Deployment to be in the Running status. [View the list of statuses](../reference/14_statuses.md).
2929

3030
</TabItem>
3131
<TabItem value="sdk-cli" label="SDK CLI">
@@ -92,9 +92,15 @@ When using custom domains with your Custom Deployment, you'll need to configure
9292
- Enter your desired custom domain (e.g., example.com for top-level domain or app.example.com for subdomain).
9393
- Save the changes to update your Custom Deployment settings.
9494

95-
2. **Configure DNS Records**:
95+
2. **Obtain Your Application's Hostname**: After adding your custom domain, the SettleMint platform will provide you with an ALIAS (for top-level domains) or CNAME (for subdomains) record. This can be found in the "Connect" tab of your Custom Deployment.
96+
97+
3. **Access Your Domain's DNS Settings**: Log in to your domain registrar or DNS provider's control panel.
98+
99+
4. **Configure DNS Records**:
96100

97101
For Top-Level Domains (e.g., example.com):
102+
- Remove any existing A and AAAA records for the domain you're configuring.
103+
- Remove any existing A and AAAA records for the www domain (e.g., www.example.com) if you're using it.
98104
```
99105
ALIAS example.com gke-europe.settlemint.com
100106
ALIAS www.example.com gke-europe.settlemint.com
@@ -105,6 +111,20 @@ When using custom domains with your Custom Deployment, you'll need to configure
105111
CNAME app.example.com gke-europe.settlemint.com
106112
```
107113

114+
5. **Set TTL (Time to Live)**:
115+
- Set a lower TTL (e.g., 300 seconds) initially to allow for quicker propagation.
116+
- You can increase it later for better caching (e.g., 3600 seconds).
117+
118+
6. **Verify DNS Propagation**:
119+
- Use online DNS lookup tools to check if your DNS changes have propagated.
120+
- Note that DNS propagation can take up to 48 hours, although it's often much quicker.
121+
122+
7. **SSL/TLS Configuration**:
123+
- The SettleMint platform typically handles SSL/TLS certificates automatically for both top-level domains and subdomains.
124+
- If you need to use your own certificates, please contact us for assistance and further instructions.
125+
126+
Note: The configuration process is similar for both top-level domains and subdomains. The main difference lies in the type of DNS record you create (ALIAS for top-level domains, CNAME for subdomains) and whether you need to remove existing records.
127+
108128
## Manage Custom Deployments
109129

110130
<Tabs>
@@ -173,7 +193,7 @@ When using Custom Deployment, keep the following limitations in mind:
173193
1. **No Root User Privileges**: Your application will run without root user privileges for security reasons.
174194

175195
2. **Read-Only Filesystem**: The filesystem is read-only. For data persistence, consider using:
176-
- Hasura: A GraphQL engine that provides a scalable database solution
196+
- Hasura: A GraphQL engine that provides a scalable database solution. See [Hasura](./9_hasura-backend-as-a-service.md).
177197
- Other External Services: Depending on your specific needs, you may use other cloud-based storage or database services
178198

179199
3. **Stateless Applications**: Your applications should be designed to be stateless. This ensures better scalability and reliability in a cloud environment.
@@ -187,6 +207,8 @@ When using Custom Deployment, keep the following limitations in mind:
187207
- Implement proper logging to facilitate debugging and monitoring
188208
- Regularly update your container images to include the latest security patches
189209

210+
Custom Deployment offers a powerful way to extend the capabilities of your blockchain solutions on the SettleMint platform. By following these guidelines and best practices, you can seamlessly integrate your custom applications into your blockchain ecosystem.
211+
190212
:::info Note
191213
Custom Deployments support automatic SSL/TLS certificate management for custom domains.
192214
:::

docs/using-platform/9_hasura-backend-as-a-service.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,200 @@ hasura metadata reload
160160

161161
For more on Hasura Metadata, refer: https://hasura.io/docs/latest/migrations-metadata-seeds/manage-metadata/
162162
For more on Hasura Migrations, refer: https://hasura.io/docs/latest/migrations-metadata-seeds/manage-migrations/
163+
164+
## Usage Examples
165+
166+
You can interact with your Hasura database in two ways: through the GraphQL API (recommended) or directly via PostgreSQL connection.
167+
168+
<Tabs>
169+
<TabItem value="graphql" label="GraphQL API (Recommended)">
170+
171+
```javascript
172+
import fetch from 'node-fetch';
173+
174+
// Configure your authentication details
175+
const HASURA_ENDPOINT = "YOUR_HASURA_ENDPOINT";
176+
const HASURA_ADMIN_SECRET = "YOUR_HASURA_ADMIN_SECRET"; // Found in the "Connect" tab of Hasura console
177+
const APP_ACCESS_TOKEN = "YOUR_APP_ACCESS_TOKEN"; // Generated following the Application Access Tokens guide
178+
179+
// Reusable function to make GraphQL requests
180+
async function fetchGraphQL(operationsDoc, operationName, variables) {
181+
try {
182+
const result = await fetch(
183+
HASURA_ENDPOINT,
184+
{
185+
method: "POST",
186+
headers: {
187+
'Content-Type': 'application/json',
188+
'x-hasura-admin-secret': HASURA_ADMIN_SECRET,
189+
'x-auth-token': APP_ACCESS_TOKEN
190+
},
191+
body: JSON.stringify({
192+
query: operationsDoc,
193+
variables: variables,
194+
operationName: operationName
195+
})
196+
}
197+
);
198+
199+
if (!result.ok) {
200+
const text = await result.text();
201+
throw new Error(`HTTP error! status: ${result.status}, body: ${text}`);
202+
}
203+
204+
return await result.json();
205+
} catch (error) {
206+
console.error('Request failed:', error);
207+
throw error;
208+
}
209+
}
210+
211+
// Query to fetch verification records
212+
const operationsDoc = `
213+
query MyQuery {
214+
verification {
215+
id
216+
}
217+
}
218+
`;
219+
220+
// Mutation to insert a new verification record
221+
const insertOperationDoc = `
222+
mutation InsertVerification($name: String!, $status: String!) {
223+
insert_verification_one(object: {name: $name, status: $status}) {
224+
id
225+
name
226+
status
227+
}
228+
}
229+
`;
230+
231+
// Function to fetch verification records
232+
async function main() {
233+
try {
234+
const { errors, data } = await fetchGraphQL(operationsDoc, "MyQuery", {});
235+
236+
if (errors) {
237+
console.error('GraphQL Errors:', errors);
238+
return;
239+
}
240+
241+
console.log('Data:', data);
242+
} catch (error) {
243+
console.error('Failed:', error);
244+
}
245+
}
246+
247+
// Function to insert a new verification record
248+
async function insertWithGraphQL() {
249+
try {
250+
const { errors, data } = await fetchGraphQL(
251+
insertOperationDoc,
252+
"InsertVerification",
253+
{
254+
name: "Test User",
255+
status: "pending"
256+
}
257+
);
258+
259+
if (errors) {
260+
console.error('GraphQL Errors:', errors);
261+
return;
262+
}
263+
264+
console.log('Inserted Data:', data);
265+
} catch (error) {
266+
console.error('Failed:', error);
267+
}
268+
}
269+
270+
// Execute both query and mutation
271+
main();
272+
insertWithGraphQL();
273+
```
274+
275+
</TabItem>
276+
<TabItem value="postgresql" label="Direct PostgreSQL Connection">
277+
278+
```javascript
279+
import pkg from 'pg';
280+
const { Pool } = pkg;
281+
282+
// Initialize PostgreSQL connection (get connection string from Hasura console -> "Connect" tab)
283+
const pool = new Pool({
284+
connectionString: 'YOUR_POSTGRES_CONNECTION_STRING'
285+
});
286+
287+
// Simple query to read all records from verification table
288+
const readData = async () => {
289+
const query = 'SELECT * FROM verification';
290+
const result = await pool.query(query);
291+
console.log('Current Data:', result.rows);
292+
};
293+
294+
// Insert a new verification record with sample data
295+
const insertData = async () => {
296+
const query = `
297+
INSERT INTO verification (id, identifier, value, created_at, expires_at)
298+
VALUES ($1, $2, $3, $4, $5)
299+
RETURNING *`;
300+
301+
// Sample values - modify according to your needs
302+
const values = [
303+
'test-id-123',
304+
'test-identifier',
305+
'test-value',
306+
new Date(),
307+
new Date(Date.now() + 24 * 60 * 60 * 1000) // Sets expiry to 24h from now
308+
];
309+
310+
const result = await pool.query(query, values);
311+
console.log('Inserted:', result.rows[0]);
312+
};
313+
314+
// Update an existing record by ID
315+
const updateData = async () => {
316+
const query = `
317+
UPDATE verification
318+
SET value = $1, updated_at = $2
319+
WHERE id = $3
320+
RETURNING *`;
321+
322+
const values = ['updated-value', new Date(), 'test-id-123'];
323+
const result = await pool.query(query, values);
324+
console.log('Updated:', result.rows[0]);
325+
};
326+
327+
// Execute all operations in sequence
328+
async function main() {
329+
try {
330+
await readData();
331+
await insertData();
332+
await updateData();
333+
await readData();
334+
} finally {
335+
await pool.end(); // Close database connection
336+
}
337+
}
338+
339+
main();
340+
```
341+
342+
</TabItem>
343+
</Tabs>
344+
345+
### Authentication Setup
346+
347+
To run these examples, you'll need the following:
348+
349+
For GraphQL API:
350+
1. **Hasura Admin Secret**: Found in the "Connect" tab of Hasura console
351+
2. **Application Access Token**: Generate this by following our [Application Access Tokens guide](16_application-access-tokens.md)
352+
353+
For PostgreSQL:
354+
1. **PostgreSQL Connection String**: Found in the "Connect" tab of Hasura console under "Database URL"
355+
356+
357+
:::warning
358+
Always keep your credentials secure and never expose them in client-side code. Use environment variables or a secure configuration management system in production environments.
359+
:::

0 commit comments

Comments
 (0)