Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Adding Support for Custom GraphQL Types and Resolvers in Firebase Data Connect #7894

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

1amageek
Copy link

@1amageek 1amageek commented Nov 1, 2024

Description

This PR adds support for custom scalar types and resolvers in Firebase Data Connect. The implementation includes:

  1. Schema configuration
  • Added customTypes and resolvers fields to SchemaYaml interface
  • Added validation for custom type definitions and resolver functions
  • Updated schema YAML parser to support the new fields
  1. Emulator Integration
  • Added new endpoints to configure custom types and resolvers in the emulator
  • Added validation layer for custom type and resolver configurations
  • Implemented error handling for configuration failures
  1. Known Limitation
    Currently, there's an issue with the emulator binary where it returns an error when using custom scalar types:
Does not support customized scalar type: [Type]

This is a limitation in the current emulator binary and will require updates to the emulator itself to fully support custom types.

Example Configuration:

schema:
  source: "./schema"
  datasource:
    postgresql:
      database: "mydb"
      cloudSql:
        instanceId: "instance-id"
  customTypes:
    Time:
      sqlType: "time"
      graphqlType: "String"
      serialize: "(time) => time.toISOString().split('T')[1]"
      parseValue: "(value) => new Date(`1970-01-01T${value}`)"
  resolvers:
    "Query.currentTime": "(parent, args, context) => new Date().toISOString()"

GraphQL Schema Usage:

scalar Time

type Sample @table(name: "Samples") {
  time: Time
}

Scenarios Tested

Note: The current PR only includes tests in validate.spec.ts. Additional testing, particularly for emulator integration, is recommended.

Sample Commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant