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

Can't add a payment provider w/o modifying core #4759

Closed
jamesporl opened this issue Oct 19, 2018 · 13 comments
Closed

Can't add a payment provider w/o modifying core #4759

jamesporl opened this issue Oct 19, 2018 · 13 comments
Milestone

Comments

@jamesporl
Copy link
Contributor

jamesporl commented Oct 19, 2018

Issue Description

Currently the available payment methods are hard-coded into the Reaction Meteor app. This means that plugins have no way of extending it to add or remove a payment method.

Comments in the code seem to indicate that extend union and extend enum were meant to be used here but these are currently unimplemented.

Current code in imports/plugins/core/payments/server/no-meteor/schemas/schema.graphql looks like this:

# These should be defined in their respective plugin schemas, but `extend union` isn't working yet
union PaymentData = ExampleIOUPaymentData | StripeCardPaymentData | MarketplaceStripeCardPaymentData | RadialCardPaymentData

# These should be defined in their respective plugin schemas, but `extend enum` isn't working yet
"The name of a payment method, which is how payment methods are keyed"
enum PaymentMethodName {
  iou_example
  stripe_card
}

My solution at the moment is to write custom code into this file which can be avoided if both extend union and extend enum are supported.

Versions

Node: 10.10.0
NPM: 5.6.0
Meteor Node: 8.11.4
Meteor NPM: 6.4.1
Reaction CLI: 0.29.0
Reaction: 2.0.0
Reaction branch: master
Docker: 18.06.1-ce
@aldeed
Copy link
Contributor

aldeed commented Oct 22, 2018

Note that this is a limitation of the Node GraphQL library. It's part of the official GraphQL spec but not the official GraphQL Node library yet.

I do plan to try updating to the latest version of that, but it's unclear whether they have added support for these extensions yet.

@spencern
Copy link
Contributor

spencern commented Nov 5, 2018

It appears that v14.x included support for extending enums and unions based on graphql/graphql-js#1095 being closed by graphql/graphql-js#1373 and the release notes for v14.0.0

There are breaking changes in this version of GraphQL, so it's unclear what our path to this is, but the first step would be someone trying it out and noting what breaks.

@jamesporl
Copy link
Contributor Author

jamesporl commented Nov 5, 2018

I tried upgrading to 14.0.2. Both extend enum and extend union still don't work. Are there other steps that I need to do?

@aldeed
Copy link
Contributor

aldeed commented Nov 5, 2018

@ajporlante I believe we don't actually check PaymentMethodName enum right now due to this issue, so you could just not extend it. PaymentData might still be checked so we could change that to a JSONObject type for now to work around that issue. If this hasn't yet been implemented in the JavaScript lib, then there isn't much else we can do

@brent-hoover brent-hoover changed the title Support for extend union and extend enum Can't add a payment provider w/o modifying core Nov 8, 2018
@spencern
Copy link
Contributor

spencern commented Nov 8, 2018

@ajporlante did 14.0.2 not implement extend enum or extend union or are there other issues you're facing here?

@jamesporl
Copy link
Contributor Author

@spencern yes, I see that 14.0.2 implemented extend enum and extend union.

But like I said, I tried using this version and extend enum and extend union still don't work in Reaction. Maybe, I am missing some other configuration?

I am honestly not sure what to do next. @aldeed 's solution will surely work, but it requires patching some core code.

@spencern
Copy link
Contributor

spencern commented Nov 8, 2018

If 14.0.2 implemented the missing functionality, then we should be able to extend these within in Reaction Commerce. There may need to be a spike to learn how we're extending other parts of our GraphQL schema right now, but I don't see why we should use a work-around.

@rosshadden
Copy link
Contributor

@ajporlante You shouldn't need to modify core to do what I think you are trying to do, or at least that was the goal.

Although the PaymentMethodName enum exists in that file, it is unused. Instead, PaymentMethod@name is a String until our GraphQL library supports extending enums and unions.
The PaymentData union is actually used, but we can do what @aldeed said for now and either change the type of Payment@data to be JsonObject, or add JsonObject to the existing PaymentData union.

Upgrading GraphQL would be great, but not doing so (yet) shouldn't prevent you from doing what you need to.

@brent-hoover
Copy link
Collaborator

@ajporlante Can you verify that if we can make the above change to Payment@data that we can add this payment method w/o modifying core? If so we can just make that change and move forward.

@aldeed
Copy link
Contributor

aldeed commented Nov 9, 2018

@ajporlante If you did not, try bumping the graphql-tools version to 4.0.3 as well. https://github.com/apollographql/graphql-tools/blob/master/CHANGELOG.md

@aldeed
Copy link
Contributor

aldeed commented Nov 9, 2018

The only other pkgs that might impact it working would be apollo-server-core and apollo-server-express, but I think there may be breaking changes to their APIs in 2.x. We should get on 2.x eventually, though, so if you want to try it...

I would probably bump all of the graphql- packages to their latest to be safe. Then the whole thing could be tested at once if you submit a PR with those updates.

@jamesporl
Copy link
Contributor Author

@aldeed These changes seem to make things work:

"graphql": "14.0.2",
"graphql-tools": "4.0.3",

I just had to remove some redundant definitions in the core schema. I will create a PR for these updates.

Having said these, @zenweasel @rosshadden we don't have to modify PaymentData. With the dependency update, we can extend payment schema in custom plugins without modifying core code.

@brent-hoover
Copy link
Collaborator

@ajporlante Great! Let's just make sure let's keep an eye out for any issues and give this a good test. I think this results in a much cleaner and easier to understand API

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

No branches or pull requests

6 participants