April 2020 Summaries
9 posts from Hasura
Filter
Month:
Year:
Post Summaries
Back to Blog
This article discusses implementing CouchDB style conflict resolution with Postgres (central backend database) and PouchDB (frontend app user database). Conflict resolution is an aspect of taking multiple simultaneous changes, which may be conflicting, and merging them into one change. The author explains how to use RxDB on the frontend and pair it with Hasura to build powerful apps with great user-experience. They also provide a detailed guide on implementing custom conflict resolution strategies using Hasura.
Apr 28, 2020
2,788 words in the original blog post.
The article delves into creating authorization rules for a multi-tenant system using Google Cloud Platform's (GCP) hierarchical role-based access control system. It emphasizes the need for users to access only resources within their tenant, with roles varying per tenant. The structure includes a projects table, users table, roles table, and mappings for user roles across projects and storage buckets. By flattening hierarchical roles, users can be assigned multiple permissions, such as storage_admin, storage_editor, and storage_viewer, depending on their role. The article provides SQL-based examples using Hasura's permission system to set up select, update, delete, and insert permissions for storage buckets. It also covers permissions for assigning or removing user roles, highlighting the use of role_admin and role_viewer roles. The overall approach leverages Postgres Views and Hasura's Permission DSL to efficiently manage a multi-tenant authorization system.
Apr 21, 2020
1,105 words in the original blog post.
In this article, we explore how to add custom business logic to Hasura using Actions and the programming platform Dark. We create a custom mutation for an online mafia game that assigns roles to players while ensuring certain constraints are met. The process involves defining the mutation, creating an HTTP endpoint in Dark, implementing the handler, and testing it by sending requests. We also demonstrate how to modify the definition of the mutation to return additional information about the game and connect it to the graph using a new relationship.
Apr 16, 2020
1,254 words in the original blog post.
In this article, we will discuss how to compile GraphQL schemas for optimal performance. We will also explore the limitations of using Dataloader and why it is not enough to ensure efficient query execution in a production environment.
## Introduction
GraphQL has become increasingly popular as an alternative to REST APIs due to its ability to provide exactly what clients need, reducing over-fetching and under-fetching issues. However, one of the challenges with GraphQL is ensuring optimal performance when dealing with complex queries that involve multiple resolvers and data sources.
Dataloader is a utility library developed by Facebook for batching and caching requests to remote data sources in order to improve query performance. While Dataloader can help address some of these challenges, it has its limitations and may not be sufficient on its own to ensure efficient query execution in a production environment.
In this article, we will discuss how to compile GraphQL schemas for optimal performance using tools like `graphql-compile` and `graphql-gen`, which can help generate code that is tailored specifically for your application's data access patterns. We will also explore some additional techniques you can use alongside Dataloader to further optimize query performance.
## Compiling GraphQL Schemas
One approach to improving the performance of GraphQL queries is to compile the schema into a format that is more efficient for execution. This involves analyzing the structure of your schema and generating code that takes advantage of this knowledge to execute queries more quickly.
There are several tools available for compiling GraphQL schemas, including:
- `graphql-compile`: A command-line tool that can compile a GraphQL schema into various formats, such as JSON or TypeScript interfaces.
- `graphql-gen`: A library that provides programmatic access to the functionality of `graphql-compile`, allowing you to integrate it directly into your application's build process.
By using these tools, you can generate code that is tailored specifically for your application's data access patterns, which can help improve query performance by reducing unnecessary computations and memory allocations.
## Limitations of Dataloader
While Dataloader can be very effective at batching and caching requests to remote data sources, it does have some limitations that may prevent you from achieving optimal query performance in a production environment:
1. **Lack of Context**: Dataloader operates independently of the context in which queries are being executed. This means that it cannot take advantage of any additional information about the current state of your application or its data sources, such as whether certain resources have already been loaded into memory.
2. **Static Data Access Patterns**: Dataloader assumes that all queries will follow the same data access patterns, which may not always be true in practice. For example, if you are building a dashboard-style application where users can customize their own views of the underlying data, then it is likely that different users will have very different query requirements.
3. **Complexity**: Implementing Dataloader correctly can be quite complex, especially when dealing with more advanced features like batching and caching across multiple resolvers or data sources. This complexity can make it difficult to ensure that your implementation is both efficient and correct.
To address these limitations, you may want to consider using additional techniques alongside Dataloader, such as:
- **Schema Compilation**: As discussed earlier in this article, compiling your GraphQL schema into a more efficient format can help improve query performance by reducing unnecessary computations and memory allocations.
- **Dynamic Data Access Patterns**: Instead of assuming that all queries will follow the same data access patterns, you may want to consider implementing dynamic data loading strategies that are tailored specifically for each individual user or query context. This could involve using techniques like memoization or lazy evaluation to avoid redundant computations and memory allocations.
- **Optimized Data Structures**: In some cases, it may be possible to improve query performance by optimizing the data structures used to represent your application's underlying data sources. For example, if you are working with a relational database, then you might want to consider using indexes or other performance optimization techniques to speed up data retrieval operations.
By combining these different approaches, you can help ensure that your GraphQL queries are executed as efficiently as possible in a production environment.
## Conclusion
In this article, we have discussed how to compile GraphQL schemas for optimal performance using tools like `graphql-compile` and `graphql-gen`. We have also explored the limitations of using Dataloader alone and why it is not enough to ensure efficient query execution in a production environment. By combining schema compilation with dynamic data loading strategies and optimized data structures, you can help improve the performance of your GraphQL queries and deliver a better user experience for your applications' end users.
25 Oct, 2023
9 MIN READ
Compiling GraphQL for optimal performance: going beyond Dataloader
07 Sep, 2023
8 MIN READ```
SUMMARY:
Apr 14, 2020
2,716 words in the original blog post.
The text discusses the process of benchmarking and optimizing performance in a running graphql-engine. It highlights how power management can skew measurements during benchmarking and provides tips on how to maximize performance and maintain consistent latency. Techniques such as using "performance" p-state governor, prohibiting deep sleep states, and isolating the engine on particular CPUs are explored. The text also mentions some techniques that seemed ineffective or not practical for actual deployment but could potentially provide more stable (and slower) latencies.
Apr 14, 2020
1,481 words in the original blog post.
Over 15 online events are scheduled for April to discuss GraphQL and Hasura topics. Events cater to various audiences, including Hasura users, developers using GraphQL in large organizations or enterprises, developers new to GraphQL, and those looking to enhance their GraphQL skills. Topics covered include migration from legacy stacks to GraphQL using Hasura, performance and monitoring tips/tricks with GraphQL, authorization and security patterns for GraphQL, event-driven applications with GraphQL and serverless, realtime GraphQL and serverless made easy for React with Hasura, building an offline-first React app with RxDB & Hasura, and integrating business logic into your GraphQL API with Hasura Actions.
Apr 13, 2020
491 words in the original blog post.
In this three-part video series, Baris Tumerkan and Sezgi Ulucam collaborate to build a Unity leaderboard using Hasura. They learn about each other's expertise in GraphQL and Unity while working on the project. The team discovers how easy it is to set up queries, mutations, and subscriptions with the Unity GraphQL client by Tade Ajiboye. They also use Hasura Actions for customizing business logic for high scores. Along the way, they encounter bugs and solve them, making the process informative for viewers who may want to code along at home. The project includes setting up a Postgres database with Hasura, displaying top scores on the leaderboard UI, showing live scores using GraphQL subscriptions, and implementing business logic for high scores using Hasura Actions.
Apr 09, 2020
368 words in the original blog post.
A special series of GraphQL online events called "GraphQL Fireside Chats" is being co-hosted by This Dot starting on April 14th. Each week, a different topic related to GraphQL will be discussed in a roundtable format with special guests and Q&A sessions. The purpose of these events is to bring the GraphQL community together for discussion and collaboration. Topics include platform and data centric use cases, performance and monitoring tips/tricks/caveats, authorization and security patterns, and event-driven applications with GraphQL & serverless. Interested attendees can sign up for each event to receive a live link on the day of the stream.
Apr 07, 2020
232 words in the original blog post.
In this tutorial, we will learn how to build a real-time geolocation app using Hasura GraphQL and PostGIS. The complexities involved in building such an application include managing large datasets in the database, ease of API consumption, and real-time frontend rendering. By leveraging Postgres's capabilities via functions and its extensibility through PostGIS, along with Hasura providing a neat GraphQL API for clients to consume, we can create a data-heavy real-time geo-location app that plots nearby restaurants on a map.
To set up the backend, we will be running a Postgres database and seeding some location data from OpenStreetMap. We will also create a Postgres function to query nearby data. On the frontend, we will be using a React app with Apollo Client integration to query for location data using Hasura GraphQL API.
To begin, set up Hasura and Postgres with PostGIS extension by cloning the sample app, running GraphQL Engine locally, installing Hasura CLI, and configuring the Hasura endpoint in the `config.yaml` file. Seed location data from OpenStreetMap for Bangalore or a different city if desired.
Next, create a Postgres function to fetch nearby data using PostGIS functions like ST_TRANSFORM, ST_DWITHIN, and ST_X/ST_Y. This function will accept latitude, longitude, and bound range arguments to calculate nearby locations within the specified distance.
On the frontend, integrate a GraphQL client for React, such as Apollo Client, and set up the necessary GraphQL query to fetch the restaurants using the Postgres function. To render the map on React, use libraries like React Leaflet.
By utilizing Hasura's capabilities with Postgres and PostGIS, we can create a powerful real-time geolocation app that efficiently handles large datasets and provides an easy-to-consume API for clients.
Apr 01, 2020
986 words in the original blog post.