Apollo Client Cache vs. Redux

You’re comparing apples to oranges. Yes, at a high level both redux and apollo-client provide a way for you to manage global application state. However, redux allows you to create a predictable state container that changes in response to the actions you define. That means redux offers: Predictability. Reducers are pure functions — given the … Read more

expressGraphQL is not a function

Please replace your expressGraphQL with graphqlHTTP as it was destructured Use: const { graphqlHTTP } = require(‘express-graphql’); or const expressGraphQL = require(‘express-graphql’).graphqlHTTP This is because a method called graphqlHTTP exist in the express-graphql module and you are destructure with another method name that does not exist in the module I also noticed that you have … Read more

Does apollo-client work on node.js?

Apollo Client should work just fine on Node. You only have to install cross-fetch. Here is a complete TypeScript implementation of Apollo Client working on Node.js. import { ApolloClient, gql, HttpLink, InMemoryCache } from “@apollo/client”; import { InsertJob } from “./graphql-types”; import fetch from “cross-fetch”; const client = new ApolloClient({ link: new HttpLink({ uri: process.env.PRODUCTION_GRAPHQL_URL, … Read more

GraphQL dynamic query building

GraqhQL provides directives for this very purpose. Create a fragment to define common fields, use @include(if: Boolean) and @skip(if: Boolean) directives on that fragment to get dynamic fields. By dynamic fields we mean fields that are known at execution time. According to spec, it is best to avoid manual string interpolation to construct dynamic queries. … Read more

Why am I getting a “Cannot return null for non-nullable field” error when doing a mutation? [duplicate]

The biggest problem with your resolver is that in any number of scenarios, instead of returning a User object, you return a string. Your schema specifies that createAccount can return a User or null (if it was User!, it would be non-nullable and then null would not be a valid type either). When you return … Read more

Notable differences between buildSchema and GraphQLSchema?

The buildSchema function takes a schema in SDL (schema definition language) and returns a GraphQLSchema object. Given two identical schemas generated with each method, runtime performance would be the same. Startup time for a server using buildSchema would be slower since parsing the SDL adds an extra step that would not otherwise exist — whether … Read more