How can I integrate a GraphQLInputObject into a schema loaded dynamically using JavaScript?

16 Views Asked by At
async function _loadSchema() {
    const typeDefs = await loadSchema(path.join(__dirname, '../graphql/typedefs/*.graphql'), {
        loaders: [
            new GraphQLFileLoader()
        ]
    });
    const resolvers = await loadFiles(path.join(__dirname, '../graphql/resolvers'));

    const schema = makeExecutableSchema({ typeDefs, resolvers });

    return applyMiddleware(schema, shield);
}

This is my LoadSchema function. It loads GraphQL type definitions from files and resolvers from JavaScript files.

Now, within this schema, there's a 'user' query that requires an input type named 'UserQueryInput'. This input type needs to be defined in JavaScript.

const UserQueryInput = new GraphQLInputObjectType({
    name: 'UserQueryInput',
    fields: {
        // Here GraphQLString type is just for example
        where: {type: GraphQLString},
        select: {type: GraphQLString},
    }
})

I've created a GraphQLInputObject in JavaScript named 'UserQueryInput'.

So, how do I seamlessly incorporate this input type into my schema?

0

There are 0 best solutions below