🎬 That's a Wrap for GraphQLConf 2024! • Watch the Videos • Check out the recorded talks and workshops

Code Using GraphQL

Sort by:
GraphQL.js
The reference implementation of the GraphQL specification, designed for running GraphQL in a Node.js environment.
Last release 2 days ago20kMIT License
README

To run a GraphQL.js hello world script from the command line:

npm install graphql

Then run node hello.js with this code in hello.js:

var { graphql, buildSchema } = require("graphql")
 
var schema = buildSchema(`
  type Query {
    hello: String
  }
`)
 
var rootValue = { hello: () => "Hello world!" }
 
var source = "{ hello }"
 
graphql({ schema, source, rootValue }).then(response => {
  console.log(response)
})
Apollo Server
A GraphQL server from Apollo that works with any Node.js HTTP framework
Last release 1 month ago14kMIT License
README

To run a hello world server with Apollo Server:

npm install @apollo/server graphql

Then run node server.js with this code in server.js:

import { ApolloServer } from "@apollo/server"
import { startStandaloneServer } from "@apollo/server/standalone"
 
const server = new ApolloServer({
  typeDefs,
  resolvers,
})
 
const { url } = await startStandaloneServer(server)
 
console.log(`🚀 Server ready at ${url}`)

Apollo Server has a built in standalone HTTP server and middleware for Express, and has an framework integration API that supports all Node.js HTTP server frameworks and serverless environments via community integrations.

Apollo Server has a plugin API, integration with Apollo Studio, and performance and security features such as caching, automatic persisted queries, and CSRF prevention.

graphql-yoga
GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant GraphQL Server using Envelop and GraphQL Tools.
Last release 3 days ago8kMIT License
README
  • Built around the Fetch API Request & Response objects
  • GraphQL over HTTP compliant
  • Extensible GraphQL Engine powered by Envelop
  • GraphQL Subscriptions over HTTP
  • Handle file uploads with GraphQL
  • Integrates with AWS Lambda, Cloudflare Workers, Deno, Express, Next.js, SvelteKit, and more.

To run a hello world server with graphql-yoga:

npm install graphql-yoga graphql

Then create a server using the createServer import:

import { createServer } from "http"
import { createSchema, createYoga } from "graphql-yoga"
 
createServer(
  createYoga({
    schema: createSchema({
      typeDefs: /* GraphQL */ `
        type Query {
          hello: String
        }
      `,
      resolvers: {
        Query: {
          hello: () => "Hello Hello Hello",
        },
      },
    }),
  }),
).listen(4000, () => {
  console.info("GraphQL Yoga is listening on http://localhost:4000/graphql")
})

Depending on your deployment target, you may need to use an additional library. See the documentation for further details.

Mercurius
Mercurius is a flexible and extendible GraphQL adapter for Fastify, a blazing-fast web framework with the least overhead and a powerful plugin architecture.
Last release 2 months ago2kMIT License
README

To run an hello world script with mercurius:

npm install fastify mercurius

Then run node app.js with this code in app.js:

const Fastify = require("fastify")
const mercurius = require("mercurius")
 
const schema = `
  type Query {
    hello(name: String): String!
  }
`
 
const resolvers = {
  Query: {
    hello: async (_, { name }) => `hello ${name || "world"}`,
  },
}
 
const app = Fastify()
app.register(mercurius, {
  schema,
  resolvers,
})
 
app.listen(3000)
 
// Call IT!
// curl 'http://localhost:3000/graphql' \
//  -H 'content-type: application/json' \
//  --data-raw '{"query":"{ hello(name:\"Marcurius\") }" }'
GraphQL-WS
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Last release 8 months ago2kMIT License
GraphQL-SSE
Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client.
Last release 8 months ago396MIT License
GraphQL-HTTP
Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.
Last release 3 weeks ago322MIT License
Pylon
A code-first framework for GraphQL API development, where your schema reflects your functionality. Run npm create pylon@latest to get started.
Last release 6 days ago183Apache License 2.0
README
  1. Create
npm create pylon@latest
  1. Develop

Example service:

import { app } from "@getcronit/pylon"
 
class User {
  name: string
  email: string
  constructor(name: string, email: string) {
    this.name = name
    this.email = email
  }
}
 
const users = [
  new User("Alice", "alice@example.com"),
  new User("Bob", "bob@example.com"),
  new User("Charlie", "charlie@example.com"),
]
 
export const graphql = {
  Query: {
    users,
    user: (name: string) => {
      return users.find(user => user.name === name)
    },
  },
  Mutation: {
    addUser: (name: string, email: string) => {
      const user = new User(name, email)
      users.push(user)
      return user
    },
  },
}
 
export default app
  1. Query
query User {
  user(name: "Alice") {
    name
    email
  }
}
 
query Users {
  users {
    name
    email
  }
}
 
mutation AddUser {
  addUser(name: "Corina", email: "corina@example.com") {
    name
    email
  }
}
GraphQLBox server
An extensible GraphQL server with modules for caching, request parsing, debugging, subscriptions and more...
25MIT License
README

The example below installs and initializes the GraphQLBox server with a persisted cache and debugging enabled.

npm install @graphql-box/core @graphql-box/server @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/execute @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/redis @cachemap/constants @cachemap/types
import Cachemap from "@cachemap/core"
import redis from "@cachemap/redis"
import reaper from "@cachemap/reaper"
import CacheManager from "@graphql-box/cache-manager"
import Client from "@graphql-box/client"
import DebugManager from "@graphql-box/debug-manager"
import Execute from "@graphql-box/execute"
import RequestParser from "@graphql-box/request-parser"
import Server from "@graphql-box/server"
import { makeExecutableSchema } from "@graphql-tools/schema"
import { performance } from "perf_hooks"
import { schemaResolvers, schemaTypeDefs } from "./schema"
import logger from "./logger"
 
const schema = makeExecutableSchema({
  typeDefs: schemaTypeDefs,
  resolvers: schemaResolvers,
})
 
const server = new Server({
  client: new Client({
    cacheManager: new CacheManager({
      cache: new Cachemap({
        name: "server-cache",
        reaper: reaper({ interval: 300000 }),
        store: redis(/* configure */),
      }),
      cascadeCacheControl: true,
      typeCacheDirectives: {
        // Add any type specific cache control directives in the format:
        // TypeName: "public, max-age=3",
      },
    }),
    debugManager: new DebugManager({
      environment: "server",
      log: (...args) => {
        logger.log(...args)
      },
      name: "SERVER",
      performance,
    }),
    requestManager: new Execute({ schema }),
    requestParser: new RequestParser({ schema }),
  }),
})
 
// Meanwhile... somewhere else in your code
 
app.use("api/graphql", graphqlServer.request())