GraphQL inline fragments

arjun_rajkumar
Excursionist
25 1 0

Hey,

I'm trying to use the appsubscription grpahql query to get details on a subscription.

This is my query:

query {
  node(id: "gid://shopify/AppSubscription/21899804867") {
    ...on AppSubscription {
      createdAt
      currentPeriodEnd
    }
  }
}

 

But getting a strange error.

Screenshot 2021-03-18 at 11.05.50 AM.png

 

I;m able to use Graphql to make other queires, just this one is failing. 

Do I need to define the AppSubscription inline fragment somewhere?

 

Thanks

 

Arjun

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 243

I don't understand why the inline portion of your request is referring back to itself. What if you remove the ...on AppSubscription (with enclosing braces)? Here is a sample of a quick test I made that appears to be formatted okay.

 

{
  appInstallations(first: 5) {
    edges {
      node {
        allSubscriptions(first: 5) {
          edges {
            node {
              createdAt
              currentPeriodEnd
              id
              name
              status
              test
            }
          }
        }
      }
    }
  }
}

 

 

0 Likes
arjun_rajkumar
Excursionist
25 1 0

Hi @Greg_Kujawa , 

Found the solution -- it was to put a space before on .. as in 

... on AppSubscription

GOt the solution from here https://github.com/github/graphql-client/issues/108 

The Shopify docs does this without a space : https://shopify.dev/docs/admin-api/graphql/reference/billing/appsubscription - hence the error.

Your solution works when we want to get the last 10 or first 10 etc.. But if we want to get one specific subscription based on ID.. I need to pass the ID no.

Thank you!

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 243

Good deal, and I see why you had to use an inline reference to the AppSubscription now. Since you were using the generic node reference as the top point of the query. Glad you got it working!

0 Likes