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

fix: Correct null id check in retrieveStripeCustomer #144

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

casey-matt
Copy link
Contributor

@casey-matt casey-matt commented Nov 9, 2024

It looks like the retrieveStripeCustomer implementation has a small bug where the conditional is flipped. My project is passing in customer ID similar to the example-store-stripe repo like this:

 <StripeProvider customer={{ id: customer }}>
    ...
 </StripeProvider>

And eventually results in a call to retrieveStripeCustomer(), which triggers this error:

api | [13:13:05.115] ERROR: Unexpectedly received null or undefined data. This may be a bug in redwoodjs-stripe.
api |
api | Please file an issue for it over here, and provide with the details given below: https://github.com/chrisvdm/redwoodjs-stripe/issues/new",
api |
api | **Context:**
api | retrieveStripeCustomer:id
api |
api | **Data:**
api | { id: '<customer_id>', addProps: null }
api |
api |     err: {
api |       "type": "GraphQLError",
api |       "message": "Unexpectedly received null or undefined data. This may be a bug in redwoodjs-stripe.\n\nPlease file an issue for it over here, and provide with the details given below: https://github.com/chrisvdm/redwoodjs-stripe/issues/new\",\n\n**Context:**\nretrieveStripeCustomer:id\n\n**Data:**\n{ id: '<customer_id>', addProps: null }\n",
api |       "stack":
api |           Error: Unexpectedly received null or undefined data. This may be a bug in redwoodjs-stripe.
api |
api |           Please file an issue for it over here, and provide with the details given below: https://github.com/chrisvdm/redwoodjs-stripe/issues/new",
api |
api |           **Context:**
api |           retrieveStripeCustomer:id
api |
api |           **Data:**
api |           { id: '<customer_id>', addProps: null }
api |
api |               at nonNilAssertionError (/Users/matt/workspace/moontower-rwjs/node_modules/@redwoodjs-stripe/api/dist/cjs/lib/nonNilAssertionError.js:25:49)
api |               at Object.retrieveStripeCustomer (/Users/matt/workspace/moontower-rwjs/node_modules/@redwoodjs-stripe/api/dist/cjs/services/customers/customers.js:44:64)
api |               at Object.retrieveStripeCustomer (/Users/matt/workspace/moontower-rwjs/node_modules/@redwoodjs/graphql-server/dist/makeMergedSchema.js:97:30)
api |               at useRedwoodDirectiveValidatorResolver (/Users/matt/workspace/moontower-rwjs/node_modules/@redwoodjs/graphql-server/dist/plugins/useRedwoodDirective.js:82:22)
api |               at executeField (/Users/matt/workspace/moontower-rwjs/node_modules/@graphql-tools/executor/cjs/execution/execute.js:324:24)
api |               at executeFields (/Users/matt/workspace/moontower-rwjs/node_modules/@graphql-tools/executor/cjs/execution/execute.js:272:28)
api |               at executeOperation (/Users/matt/workspace/moontower-rwjs/node_modules/@graphql-tools/executor/cjs/execution/execute.js:232:18)
api |               at /Users/matt/workspace/moontower-rwjs/node_modules/@graphql-tools/executor/cjs/execution/execute.js:69:64
api |               at new ValueOrPromise (/Users/matt/workspace/moontower-rwjs/node_modules/value-or-promise/src/ValueOrPromise.ts:35:15)
api |               at executeImpl (/Users/matt/workspace/moontower-rwjs/node_modules/@graphql-tools/executor/cjs/execution/execute.js:69:20)
api |       "path": [
api |         "retrieveStripeCustomer"
api |       ],
api |       "locations": [
api |         {
api |           "line": 2,
api |           "column": 3
api |         }
api |       ],
api |       "extensions": {}
api |     }
api | [13:13:05.115] DEBUG: Processing GraphQL Parameters done.
api | [13:13:05.116] INFO: request completed
api |     reqId: "req-8"
api |     res: {
api |       "statusCode": 200
api |     }
api |     responseTime: 19.324374988675117

Based on the other examples in customers.ts, this assertion is meant to catch null values (== null). It's currently flipped (!== null). If this is the intended behavior, we should use a different assertion.

@casey-matt
Copy link
Contributor Author

Hey @chrisvdm, this is a tiny 1-line change to an edge case check in the retrieveStripeCustomer function. I tested it in my application locally & it fixes the error, but you're probably better suited to know if this result in unexpected impact somewhere.

I figured I'd just submit the PR instead to make it easier, instead of filing an issue.

@chrisvdm chrisvdm merged commit a031a0e into chrisvdm:main Nov 14, 2024
1 check failed
@chrisvdm
Copy link
Owner

Hey @casey-matt, thanks so much for this. Much appreciated 👍

@chrisvdm
Copy link
Owner

Released!

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.

2 participants