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

Support users embedding fql snippets in objects and arrays #272

Merged
merged 4 commits into from
Jun 26, 2024

Conversation

ptpaterson
Copy link
Contributor

@ptpaterson ptpaterson commented Jun 12, 2024

Ticket(s): FE-3501

resolves #259

Problem

Query instances (i.e. results from the fql function) cannot be encoded when embedded in objects or arrays.

The QueryValue type is incorrectly used for types over the wire.

Solution

The database now accepts a query interpolation fragments for array and object, where the existing fql fragment can now be nested under the array and object fragments. Add new encodeInterpolation method to encode with the new fragments.

Query arguments do not use interpolation, so they still need the @object tag. Encoding arguments still uses the existing encode method.

Update types to better distinguish between

  • Arguments to be encoded
    • allow Query within objects and arrays
    • QueryValue should remain a valid QueryArgument to ensure round-trip-ability
  • Encoded values sent over the wire
    • Updated fragment types and remove QueryValue from fragments
  • Decoded values
    • Specify QueryValue type only where we decode values from Fauna.

Result

Queries can be encoded in QueryInterpolations.

Queries can be embedded within JS arrays and objects.

Type changes are corrections to the internal implementation. No user-facing changes were made to types (except QueryArgument)

Out of scope

n/a

Testing

Updated existing tests and added new ones for embedding queries in arrays and objects.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ptpaterson ptpaterson marked this pull request as ready for review June 12, 2024 21:45
Copy link
Contributor

@pnwpedro pnwpedro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small fix to a comment please. Looks good otherwise

TaggedRef,
TaggedBytes,
} from "./wire-protocol";
import { Query, QueryArgument, QueryArgumentObject } from "./query-builder";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should revisit the type/class organization at some point. We're increasing the strength of our circular dependencies. wire-protocol and tagged-type both now have more dependencies in query-builder, and query-builder already has dependencies in each.

We don't need to address in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some reorganization of types staged but I put everything back. I was worried about

  1. breaking import paths, and
  2. complicating the diff for this PR.

On further consideration of no. 1, that doesn't actually matter because we bundle the driver and only expose the exports from src/index and that's it.

So I guess my point is: agreed! We should come back to this.

Comment on lines 18 to 19
* A QueryArgument is a plain javascript object where each property is a
* valid QueryArgument.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching the copy-pasta! I've updated in 7bb285a. How's that?

@ptpaterson ptpaterson requested a review from pnwpedro June 26, 2024 17:13
@ptpaterson ptpaterson merged commit 759018d into main Jun 26, 2024
5 checks passed
@ptpaterson ptpaterson deleted the query-encoding branch June 26, 2024 17:26
@ptpaterson ptpaterson linked an issue Jun 27, 2024 that may be closed by this pull request
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.

FQL Objects with nested queries
2 participants