metatype icon indicating copy to clipboard operation
metatype copied to clipboard

fix(typegraph): prisma where fields types

Open luckasRanarison opened this issue 9 months ago • 4 comments
trafficstars

Migration notes


  • [x] The change comes with new or modified tests
  • [ ] Hard-to-understand functions have explanatory comments
  • [ ] End-user documentation is updated to reflect the change

Summary by CodeRabbit

  • New Features

    • Enhanced filtering functionality for strings with the addition of a format field in the StringFilter, allowing for customized string type definitions.
    • Added a custom string representation for StringType variants, improving clarity in type handling.
  • Tests

    • Introduced a test suite to validate the handling of invalid queries, ensuring proper error responses for incorrect input formats.

luckasRanarison avatar Feb 05 '25 07:02 luckasRanarison

📝 Walkthrough

Walkthrough

The changes introduce significant updates to the StringFilter struct by adding a new public field format of type StringType, which allows for specifying the string format. The generate method has been modified to utilize this new field, affecting how the type_id is constructed. Additionally, the name method now returns a formatted string based on the format field. The Where struct's generate method has also been updated to construct the StringFilter with the format. A new test file has been added to validate the Prisma engine's handling of invalid UUID strings in GraphQL queries.

Changes

File(s) Change Summary
src/.../prisma/type_generation/filters.rs Added a public format field to StringFilter and updated its generate and name methods to utilize this field.
src/.../prisma/type_generation/where_.rs Modified the generate method in Where to instantiate StringFilter with an explicit format derived from prop.prop_type, changing the handling of prop_type to use references.
tests/.../invalid_query_test.ts Introduced a new test suite for validating the Prisma engine's behavior with invalid UUID strings in GraphQL queries, expecting a 400 error and a specific error message.
src/.../prisma.rs Added a new implementation of the Display trait for the StringType enum, providing custom string representations for its variants.

Sequence Diagram(s)

sequenceDiagram
  participant WG as Where Generator
  participant SF as StringFilter
  WG->>SF: Instantiate StringFilter with prop.prop_type
  SF->>SF: Call generate() using the format
  SF->>SF: Compose name() using format value
  SF-->>WG: Return generated filter
sequenceDiagram
  participant Test as Test Suite
  participant Prisma as Prisma Engine
  participant DB as Database
  Test->>Prisma: Initialize engine with connection string
  Test->>DB: Drop existing schemas and reapply migrations
  Test->>Prisma: Send findRecord query with invalid UUID
  Prisma->>DB: Validate query input
  DB-->>Prisma: Return error for invalid UUID format
  Prisma-->>Test: Return 400 error with detailed message

Possibly related PRs

  • metatypedev/metatype#958: The changes in this PR enhance the StringFilter struct and its methods, which relate to the modifications in the retrieved PR that update the instantiation of StringFilter in the Where struct's generate method.

Suggested reviewers

  • Natoandro
  • michael-0acf4

📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e1b0ee2eb9ea8ac9941ac36b0d9e531cdb41fe0 and 321a3b75ba521716e77b9a5528aba9c0a219b0d8.

⛔ Files ignored due to path filters (2)
  • tests/runtimes/typegate/__snapshots__/typegate_prisma_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/typegate/__snapshots__/typegate_runtime_test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • tests/runtimes/prisma/invalid_query_test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/runtimes/prisma/invalid_query_test.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: test-full
  • GitHub Check: pre-commit

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Feb 05 '25 07:02 coderabbitai[bot]

Also do you guys think we should reuse other scalar types? EDIT: I think enforcing constraints in the where input MUST be done so all scalars should match the initial types.

luckasRanarison avatar Feb 05 '25 08:02 luckasRanarison

Oh, looking at the diff I think I did something wrong

luckasRanarison avatar Feb 05 '25 11:02 luckasRanarison