I'm using an external API as my source for data so I can't control what the keys are in the records returned. I have a record with an object like this in it:
images: {
  '50': 'https://mir-s3-cdncf.behance.net.jpg',
  '100': 'https://mir-s3-cdn-cf.behance.net/user/100/579c455d13419.jpg',
  '115': 'https://mir-s3-cdn-cf.behance.net/user/115/.jpg',
  '138': 'https://mir-s3-cdn-cf.behance.net/user/138/.jpg'
}
I can't tell what the keys are going to be in this object up front. Is there a way to handle this in a GraphQL schema?
I got this working with the package "graphql-type-json". Here is the code using that package:
// Define new JSON types.
const AppTypes = `
  scalar JSON
  scalar JSONObject
`;
// Define resolvers for the new types which point to the types from the library.
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json');
const AppResolvers = {
  JSON: GraphQLJSON,
  JSONObject: GraphQLJSONObject
};
// Use the types.
entityTree: [JSONObject]!
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With