RedwoodJS GraphQL and API Documentation

repository·main·Indexed 12 days ago

https://github.com/redwoodjs/graphql

An opinionated, full-stack framework for React-based web applications featuring a tightly integrated GraphQL API and Prisma data layer. Includes documentation on the @redwoodjs/api and @redwoodjs/api-server packages, Fastify server management via rw-server, pino-based logging with LogFormatter, and authentication provider implementations for Auth0 and Azure Active Directory.

Tokens
402.7K
Snippets
1.5K
Records
1.8K
Agent score
96%

What's inside RedwoodJS

  1. Overview of @redwoodjs/eslint-config

    main

    The @redwoodjs/eslint-config package provides a shareable set of ESLint rules and configurations designed for use in all RedwoodJS projects. It is used for both the Redwood framework itself and for applications created via create-redwood-app (CRWA).

    The configuration incorporates recommended rule presets from:

    • ESLint
    • React
    • Rules of Hooks
    • Jest

    It also includes specific stylistic preferences such as:

    • No semicolons at the end of statements
    • Trailing commas in object and array literals
    • Single quotes for strings
    • Parentheses around arrow function parameters
    • Sorted import declarations by name
    • Mandatory curly braces for block statements
  2. Overview of @redwoodjs/forms components

    main

    RedwoodJS provides a set of helper components built on top of React Hook Form. These components simplify form creation, validation, and error handling. If the helpers are not flexible enough, @redwoodjs/forms re-exports everything from React Hook Form, allowing you to use it directly.

    Core Components

    ComponentDescription
    <Form>Surrounds all components, providing form and error contexts
    <FormError>Displays error messages from the server (typically at the top of the form)
    <Label>Replaces the HTML <label> tag; supports error-styling props
    <InputField>Replaces the HTML <input> tag; supports validation and error-styling props
    <SelectField>Replaces the HTML <select> tag; supports validation and error-styling props
    <TextAreaField>Replaces the HTML <textarea> tag; supports validation and error-styling props
    <FieldError>Displays error messages for a specific field if it has validation errors
    <Submit>Replaces <button type="submit">; triggers validation and the onSubmit function

    Input Field Components

    Redwood provides specialized components for all HTML input types using the <TypeField> naming convention:

    • <ButtonField>, <CheckboxField>, <ColorField>, <DateField>, <DatetimeLocalField>, <EmailField>, <FileField>, <HiddenField>, <ImageField>, <MonthField>, <NumberField>, <PasswordField>, <RadioField>, <RangeField>, <ResetField>, <SearchField>, <SubmitField>, <TelField>, <TextField>, <TimeField>, <UrlField>, <WeekField>
    import {
      useForm,
      useFormContext,
      // Or anything else React Hook Form exports!
    } from '@redwoodjs/forms'
  3. Overview of the RedwoodJS CLI

    main
    The RedwoodJS CLI is the primary entry point for development, managing the application lifecycle from initial commit to deployment. It leverages yarn workspaces to manage the different sides of the application (e.g., api and web) and uses generators to automate the creation of code such as components and functions. It also integrates with Prisma for database management.
  4. Overview of Redwood Router

    main

    Redwood Router (RR) is the built-in routing solution for RedwoodJS applications. It is inspired by Ruby on Rails, React Router, and Reach Router, but follows an opinionated design philosophy.

    Key design principles include:

    • Centralized Route Definition: All routes are intended to be listed in a single file.
    • Limited Nesting: The router prefers a flat structure with limited nesting to make it easy to track which routes map to which pages.

    Core features include:

    • Private routes: Restricting access to specific routes based on authentication.
    • Prerendered routes: Support for static generation/prerendering.
    • Sets of routes: Ability to group related routes.
    • Navigation and History: Standard web navigation capabilities.
    • Accessibility: Built-in considerations for accessible routing.
  5. Overview of the @redwoodjs/api package

    main

    The @redwoodjs/api package is designed to make RedwoodJS serverless and multi-client ready. It provides a single, abstracted API layer that can serve multiple clients. Currently, the package exposes core functions for:

    • Services: Business logic and data orchestration.
    • Data Fetching: Integration with Prisma for database access.
    • Logging: Opinionated logging utilities.
    • Webhooks: Handling incoming webhooks.
    • Authentication: Managing user identity and access.

    While currently targeting AWS Lambda for serverless functions, the package aims to be platform-agnostic.

  6. What is @redwoodjs/storage?

    main

    The @redwoodjs/storage package provides tools for managing file uploads within a RedwoodJS API. It includes:

    • A Prisma extension that handles file lifecycle during CRUD operations and provides result extensions like .withSignedUrl().
    • Storage adapters (e.g., FileSystemStorage, Memory) to define where files are physically stored.
    • Processors (via saveFiles) that convert web File objects into storage paths compatible with Prisma.
  7. What is RedwoodRecord?

    main

    RedwoodRecord is an Experimental Object-Relational Mapping (ORM) built on top of Prisma. It is inspired by Ruby on Rails' ActiveRecord and provides a natural, high-level interface for interacting with database tables without requiring direct SQL syntax.

    Key concepts:

    • Model: A class that represents a single database table (e.g., a User model).
    • Record: A single instance of a model representing a specific row of data in the database.

    Note: Because it is experimental, the API and behavior are subject to change.

  8. Roadmap for Background Jobs

    main

    The Background Jobs feature is under active development. Future planned improvements include:

    • Additional Adapters: Support for Redis, SQS, RabbitMQ, and more.
    • RW Studio Integration: Ability to monitor the state of outstanding jobs directly in RW Studio.
    • Baremetal Integration: Monitoring workers with pm2 when jobs are enabled.
    • Recurring Jobs: Support for cron-like scheduled tasks.
    • Lifecycle Hooks: Implementation of hooks such as beforePerform(), afterPerform(), afterSuccess(), and afterFailure() to manage job execution stages.
  9. Use LogFormatter to format RedwoodJS logs

    main

    LogFormatter is a utility designed to format RedwoodJS Logger output during development, making logs more readable. It is based on pino-colada and supports Redwood-specific GraphQL log data provided by the useRedwoodLogger envelop plug-in, including:

    • Request Id
    • User-Agent
    • GraphQL Operation Name
    • GraphQL Query
    • GraphQL Data

    Log formatting is automatically enabled when running yarn rw dev.