I’m working on setting up a recurring pricing plan for my public Shopify app.
I’ve used ShopifyCLI to set up my project and I’m trying to utilize the included GraphQL flow (with some tweaks) to achieve this.
Here is my GraphQL Code:
import "isomorphic-fetch";
import { gql } from "apollo-boost";
export function RECURRING_CREATE() {
return gql`
mutation AppSubscriptionCreate(
$name: String!
$lineItems: [AppSubscriptionLineItemInput!]!
$returnUrl: URL!
) {
appSubscriptionCreate(
name: $name
returnUrl: $returnUrl
lineItems: $lineItems
) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}
`;
}
export const getSubscriptionUrl = async (client, shop) => {
const confirmationUrl = await client
.mutate({
mutation: RECURRING_CREATE(),
variables: {
name: "Unlimited Plan",
returnUrl: `${process.env.HOST}/?shop=${shop}`,
lineItems: [
{
plan: {
appRecurringPricingDetails: {
price: {
amount: 25.0,
currencyCode: "USD",
},
interval: "EVERY_30_DAYS",
},
},
},
],
},
})
.then((response) => response.data.appSubscriptionCreate.confirmationUrl)
.catch((error) => {
console.error(error);
return "/";
});
return confirmationUrl;
};
This code gets called from the server like so:
server.use(
createShopifyAuth({
apiKey: SHOPIFY_API_KEY,
secret: SHOPIFY_API_SECRET,
scopes: [SCOPES],
async afterAuth(ctx) {
// Access token and shop available in ctx.state.shopify
const { shop, accessToken } = ctx.state.shopify;
const apolloClient = createClient(shop, accessToken);
// Redirect to app with shop parameter upon auth
ctx.redirect(getSubscriptionUrl(apolloClient, shop));
},
})
);
However, when trying to install the app the server throws this error:
[GraphQL error]: Message: Internal error. Looks like something went wrong on our end.
┃ Request ID: 1829e16b-b5dd-4e45-b083-7f8ac0da1a66 (include this in support requests)., Location: undefined, Path: undefined
┃ ApolloError: GraphQL error: Internal error. Looks like something went wrong on our end.
I’ve been unable to find sufficient information about this error, that being said it appears something might be wrong with my GraphQL mutation document. I’ve tried several variations including the example on the doc’s page with no success.
Any advice? Thanks.