Matical
Matical

Reputation: 70

Apollo Client not querying custom scalar types

I've made a datasource API to fetch an external API and retrieve it in JSON format. Everything works perfectly, I can call the query in playground and get all the data.

But when I call that query from the react / apollo client side, the data from the query is always returning null. I'm guessing it has something to do with the scalar type.

Apollo Client Query

// Drops
export const GET_DROPS = gql`
    query getDrops {
        getDrops
    }
`;

Drop Resolver (Server)

import GraphQLJSON from 'graphql-type-json';

export default {
    JSON: GraphQLJSON,
    Query: {
        getDrops: async (_source, _args, { dataSources }) => {
            const data = await dataSources.dropsAPI.fetchDrops();
            return data.result.data;
        }
    }
};

Drop Schema

export default gql`
    scalar JSON

    extend type Query {
        getDrops: JSON
    }
`;

Upvotes: 3

Views: 520

Answers (1)

John Vajda
John Vajda

Reputation: 35

Apollo Client doesn't currently support custom scalar serialization on the client side at the moment. We do have an older feature requestt to add better support for them and are considering this for a future enhancement to our client library.

Feel free to follow this Github issue if you are interested in this capability, also adding a comment about your use case will help us better understand your needs as well. Thank you!

Upvotes: 1

Related Questions