JavaScript GraphQL unable to resolve nested object property

I am trying to return a graphQL query with some nested property objects in a list. Everything seems to check out, but am getting null values.

Expected datastructure response (more detail on structure here):

//Return a GraphQLList type of all objects :    
[
    {
        "subscription" : {

        },
        "customer" : {

        },
    },
]

the query: { subscriptions { subscription { id customer_id } } }

GraphQL Query Object:

var Query = new graphQL.GraphQLObjectType({
    name: 'Query',
    description: 'Root of the Schema',
    fields: {
        subscriptions: {
            type: new graphQL.GraphQLList(SubscriptionsList),
            args : {
                customer_name: { type: graphQL.GraphQLString },
                customer_id: { type: graphQL.GraphQLString }
            },
            resolve : function (source, args) {
                return getSubscriptions().then(function (res) {
                    // Shows that data is returned
                    console.log('Data: ', res.list);

                    return res.list;
                }).catch(function (err) {
                    return err;
                });
            }
        }
    }
});

Which expects to return type GraphQLList of SubscriptionsList:

var SubscriptionsList = new graphQL.GraphQLObjectType({
    name : 'SubscriptionObj',
    description : 'stuff',
    fields : function () {
        return {
            subscription : {
                type : Subscription,
                resolve : function (subscription) {
                    return  subscription;
                }
            }
        }
    }
});

Which should resolve the nested field property:

var Subscription = new graphQL.GraphQLObjectType({
    name : 'Subscription',
    description : 'stuff',
    fields : function () {
        return {
            id: {type: graphQL.GraphQLString},
            customer_id: {type: graphQL.GraphQLString}
        }
    }
});

Console.log(res.list) Output (from Query): I am definitely getting the data and structure I expect:

[ { subscription: 
     { id: 'cbdemo_lloyd-sub2',
       customer_id: 'cbdemo_lloyd',
       plan_id: 'cbdemo_nuts',
       addons: [Object],
       due_invoices_count: 0,
       shipping_address: [Object] },
    customer: {
       ...
    }
  },
  {...}
]

GraphQL Query Output:

{
  "data": {
    "subscriptions": [
      {
        "subscription": {
          "id": null,
          "customer_id": null
        }
      },
      {
        "subscription": {
          "id": null,
          "customer_id": null
        }
      },

EDIT Not really necessary, but here is the getSubscriptions() API call that returns a promise:

function getSubscriptions() {
    return new Promise(function (resolve, reject) {
        chargebee.subscription.list({
            limit : 5,
            "plan_id[is_not]" : "basic",
            "status[is]" : "active",
            "sort_by[asc]" : "created_at"
        }).request(function(error,result){
            if (error) return reject(error);
            return resolve(result);
        });
    });
}
Answer:1

Looks like you are getting abit confused, Basiclly, when you set

new graphQL.GraphQLList(SubscriptionsList),

this is already a list. which means what you really meant is

new graphQL.GraphQLList(Subscription),

Next, your subscription object does not contain any resolve logic, so i would expect it to be something like this:

var Subscription = new graphQL.GraphQLObjectType({
    name : 'Subscription',
    description : 'stuff',
    fields : function () {
        return {
            id: {
                   type: graphQL.GraphQLString,
                   resolve: function(subscription) {
                       return subscription.subscription.id;
                   }
            },
            customer_id: {
                   type: graphQL.GraphQLString,
                   resolve: function(subscription) {
                       return subscription.subscription.customer_id;
                   }
            },
        }
    }
});

What basically happens under the hood, is that GraphQL will resolve each javascript object in the list provided, using the Subscription object. each resolver there will get the javascript object as the first value, and return the basic value from it.

Answer:2

I think the resolver in your SubscriptionsList has to return subscription.subscription. I would consider changing the name of subscriptionsList, because it's quite confusing.

The way I see it, you should just have a GraphQLList(Subscription) and remove that extra level of nesting. Either that, or call the thing that contains a subscription and a customer something else.

Answer:3

I'm using graph api to search the group, here is http request: var url ="https://graph.facebook.com/search?type=group&q=house&access_token=access_token&callback=FB.__globalCallbacks....

I'm using graph api to search the group, here is http request: var url ="https://graph.facebook.com/search?type=group&q=house&access_token=access_token&callback=FB.__globalCallbacks....

  1. javascript parse json string
  2. javascript parse json array
  3. javascript parse json file
  4. javascript parse json from url
  5. javascript parse json into array
  6. javascript parse json date
  7. javascript parse json from api
  8. javascript parse json list
  9. javascript parse json map
  10. javascript parse json error
  11. javascript parse json without quotes
  12. javascript parse json into html
  13. javascript parse json array string
  14. javascript parse json with quotes
  15. javascript parse json to array of objects
  16. javascript parse json file to object
  17. javascript parse json with single quote
  18. javascript parse json array of objects example
  19. javascript parse json with escaped quotes
  20. javascript parse json multidimensional array

I can't seem to get the owl carousel onchange function to fire off. Here's a snippet of the relevant code, any ideas? HTML: <div id="my-carousel" class="owl-carousel owl-theme"> <div ...

I can't seem to get the owl carousel onchange function to fire off. Here's a snippet of the relevant code, any ideas? HTML: <div id="my-carousel" class="owl-carousel owl-theme"> <div ...

<ul class=""> <li><img src="" alt=""/></li> <li><img src="" alt=""/></li> <li><img src="" alt=""/></li> <li><img ...

<ul class=""> <li><img src="" alt=""/></li> <li><img src="" alt=""/></li> <li><img src="" alt=""/></li> <li><img ...

  1. javascript images from folder
  2. javascript images in array
  3. javascript load images from folder
  4. javascript get images from folder
  5. javascript read images from folder
  6. javascript download images from url
  7. javascript display images from folder
  8. javascript show images from directory
  9. javascript download images from website
  10. javascript load images from directory
  11. javascript display images from an array
  12. javascript add images from folder
  13. javascript show images from folder
  14. javascript extract images from pdf
  15. javascript fetch images from folder
  16. javascript get images from url
  17. javascript get images from directory
  18. javascript read images from directory
  19. javascript pull images from folder
  20. javascript stop images from loading

Running into a problem with the scrollmagic 'section wipes (natural)' activation. What I have in my wordpress theme: functions.php wp_enqueue_script( 'tweenmax' ); wp_enqueue_script( 'scrollMagic' );...

Running into a problem with the scrollmagic 'section wipes (natural)' activation. What I have in my wordpress theme: functions.php wp_enqueue_script( 'tweenmax' ); wp_enqueue_script( 'scrollMagic' );...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis