Q: What kinds of operations does Hasura support out of the box?
A: Hasura provides full CRUD (Create, Read, Update, Delete) via GraphQL, relationship-based nested queries, mutations, and real-time features. You can also define or track foreign key relationships so querying across tables works smoothly.
Q: How do I get started with Hasura + PostgreSQL in this tutorial?
A: Use Docker (or docker-compose) to run Hasura, connect to a PostgreSQL database (locally or via a service like ElephantSQL), then use Hasura’s dashboard to track tables, create or define relationships, and explore GraphQL operations via GraphiQL.
Q: What does “no-code” mean in the context of Hasura + GraphQL?
A: It means that you can spin up a GraphQL API without writing resolvers or server logic manually. Hasura introspects your PostgreSQL database schema, auto-generates queries, mutations, and real-time subscriptions, and provides a GUI to manage tables/relationships.
Q: How does the subscription get triggered in the example?
A: In the example, a createUser mutation is implemented. Whenever this mutation is called, the code publishes a “newUser” event via the PubSub, so any client subscribed to that event receives the new user data in real time.
Q: What database is used in the example, and why?
A: The tutorial uses MongoDB (via Mongoose) as the database to store user data. It’s chosen likely for simplicity and because NestJS integrates well with it.
Q: What setup is needed to enable GraphQL subscriptions in a NestJS app?
A: You need to install the GraphQL + subscription libraries (@nestjs/graphql, @nestjs/apollo, plus subscriptions-transport-ws or graphql-ws), configure your GraphQL module to enable WebSocket transport, define resolvers for subscription events in addition to queries/mutations, and use a PubSub mechanism to publish events.
Q: Why choose NestJS for real-time GraphQL subscriptions?
A: NestJS provides a modular architecture out of the box, TypeScript support, dependency injection, and built-in support for GraphQL via packages like @nestjs/graphql. It’s well-suited for scalable server applications needing structured code.
Q: What are some likely pitfalls when using subscriptions in React + Apollo?
Ensuring you unsubscribe properly when components unmount. Handling WebSocket reconnection or dropped connections. Keeping the client cache in sync when subscription events occur. Making sure backend supports subscriptions and has a matching schema.
Q: What’s the folder or component structure in the example app?
A: There’s a React app with components like a form to create new users, a list component showing users, and a table UI. The app uses a React Router for navigating between list view and form view. Subscription logic is placed in a component listening for new user registration events.
Q: What libraries/packages are needed for subscriptions in this setup?
A: According to the tutorial: @apollo/client, graphql, and a WebSocket transport library such as subscriptions-transport-ws. Also tools like Formik/Yup for form validation are used in the example.