-
Notifications
You must be signed in to change notification settings - Fork 409
feat(dc): Add executeQuery and executeMutation APIs to Data Connect #2979
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
base: master
Are you sure you want to change the base?
Conversation
Note:The integration tests have a huge diff because I moved the existing tests under a new parent |
Forgot a few changes! Didn't know that you could close and re-open :P thanks Yuchen! |
wait - need to privatize the execute API, execution should come from operation refs (in a future PR) |
user_upsert(data: { id: "fred_id", address: "32 Elm St.", name: "Fred" }) | ||
} | ||
mutation updateFredrickUserImpersonation @auth(level: USER) { | ||
mutation updateFredrickUserImpersonation @auth(level: USER, insecureReason: "test") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: These changes likely require a re-deploy on the CI project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they deff do - I'll leave this comment open to make sure it gets re-deployed! Tagging @lahirumaramba
test/unit/data-connect/data-connect-api-client-internal.spec.ts
Outdated
Show resolved
Hide resolved
test/unit/data-connect/data-connect-api-client-internal.spec.ts
Outdated
Show resolved
Hide resolved
…s, bypassing auth policies
…ions, bypassing auth policies
…nts, revert package changes
public executeQuery<Data>( | ||
name: string, | ||
options?: OperationOptions | ||
): Promise<ExecuteOperationResponse<Data>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle the method overload correctly? If I call executeQuery('myQuery', { impersonate: ... })
would it take options
as variables
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that breaks the method overload we need to perform a runtime check to differentiate them.
public executeQuery<Data, Variables>(
name: string,
variablesOrOptions?: Variables | OperationOptions,
options?: OperationOptions
): Promise<ExecuteOperationResponse<Data>> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lahirumaramba i added some unit tests in test/unit/data-connect/data-connect.spec.ts
- your suspicion is correct, without type parameters (for required or fully optional variables), the second parameter is always treated as variables. however, i believe this is WAI, and i'd like to know how you feel about keeping this behavior?
there are no options
in our Client SDK, so we don't run into this issue there, but we do have options
in our React / Angular SDKs, and they do have this behavior (see our React SDK's README description). our solution was to clearly document this and to always use type parameters in our generated code, because we didn't want to try and identify "these fields mean this must be an options object, and this one must be a variables object", since users can use any name for variable fields in their GQL files
also, while the IDE won't pick up on the error, the backend / emulators will reject requests which omit required variables or provide unrecognized variables for that specific operation. here's what shows up when testing out this scenario:
{
errorInfo: {
code: 'data-connect/query-error',
message: '$id (String) is missing $impersonate is not expected (did you mean id?)'
},
codePrefix: 'data-connect'
}
lmk your thoughts :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additional context. I think it could create a confusion to the users if we break the method overload here. Does it make sense to try an approach similar to what we did in Firestore?
firebase-admin-node/src/firestore/index.ts
Line 154 in 8c9895e
export function getFirestore( |
public executeQuery<Data>( | ||
name: string, | ||
options?: OperationOptions | ||
): Promise<ExecuteOperationResponse<Data>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that breaks the method overload we need to perform a runtime check to differentiate them.
public executeQuery<Data, Variables>(
name: string,
variablesOrOptions?: Variables | OperationOptions,
options?: OperationOptions
): Promise<ExecuteOperationResponse<Data>> {
…uteMutation() unit tests
public executeQuery<Data>( | ||
name: string, | ||
options?: OperationOptions | ||
): Promise<ExecuteOperationResponse<Data>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additional context. I think it could create a confusion to the users if we break the method overload here. Does it make sense to try an approach similar to what we did in Firestore?
firebase-admin-node/src/firestore/index.ts
Line 154 in 8c9895e
export function getFirestore( |
API Changes
executeQuery()
andexecuteMutation()
tosrc/data-connect/data-connect.ts
. These allow users to call deployed operations with impersonated auth credentials.Testing
executeGraphql*
APIsexecuteGraphql*
APIs