GraphQL inline fragments

arjun_rajkumar
Shopify Partner
54 3 6

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

Replies 3 (3)

Gregarican
Shopify Partner
1033 86 285

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
            }
          }
        }
      }
    }
  }
}

 

 

arjun_rajkumar
Shopify Partner
54 3 6

Hi @Gregarican , 

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!

Gregarican
Shopify Partner
1033 86 285

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!