How to use the graphql-schema-bindings.createSchema function in graphql-schema-bindings

To help you get started, we’ve selected a few graphql-schema-bindings examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / graphql-schema-bindings / examples / mutation / index.js View on Github external
@description('Delete a user from the array.')
  del(@arg(ID) @required id) {
    if (users[id]) {
      delete users[id];
      return true;
    }
    
    return false;
  }
}

/**
 * Now we are ready to create our ApolloServer and start listening for requests.
 */
const server = new ApolloServer({
  schema: createSchema(UserQuery, UserMutation),
//  context: new UserQuery()
});
server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
github IBM / graphql-schema-bindings / examples / xkcd / index.js View on Github external
}

  @field(Comic)
  latest() {
    return this.comic();
  }

  @field(Comic)
  async random() {
    const { number } = await this.comic();
    return this.comic(Math.floor(Math.random() * number));
  }
}

const server = new ApolloServer({
  schema: createSchema(XKCDQuery),
  context: new XKCDQuery()
});
server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
github IBM / graphql-schema-bindings / examples / github_users / index.js View on Github external
* This is our query class.  It is the entry point for all queries to our application.
 */
@type
class UserQuery {
  @field(User)
  async user(@arg(ID) id) {
    const { data } = await axios.get(`https://api.github.com/users/${id}`);
    return new User(data);
  }
}

/**
 * Now we are ready to create our ApolloServer and start listening for requests.
 */
const server = new ApolloServer({
  schema: createSchema(UserQuery),
  context: new UserQuery()
});
server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
github IBM / graphql-schema-bindings / examples / twitter / src / index.ts View on Github external
import { ApolloServer } from "apollo-server";
import { createSchema } from "graphql-schema-bindings";
import axios from "axios";
import Twitter from "./Twitter";
import getToken from "./lib/getToken";

const { TWITTER_KEY, TWITTER_SECRET } = process.env;
if (!TWITTER_KEY || !TWITTER_SECRET) {
  throw new Error(
    "Environment variables must be set: TWITTER_KEY, TWITTER_SECRET."
  );
}

export const server = new ApolloServer({
  schema: createSchema(Twitter),
  context: async () => ({
    client: axios.create({
      baseURL: "https://api.twitter.com/1.1",
      headers: { Authorization: `Bearer ${await getToken()}` }
    }),
    twitter: new Twitter()
  })
});

async function main() {
  const { url } = await server.listen();
  console.log(`Server listening at ${url}`);
}

if (!module.parent) {
  main();

graphql-schema-bindings

an opinionated graphql server format for combining schema and implementation

Apache-2.0
Latest version published 1 year ago

Package Health Score

49 / 100
Full package analysis

Similar packages