How to use the graphql-schema-bindings.description 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
@context
  context;
  
  @field(User)
  @description('Get a user from the array.')
  add(@arg(ID) @required id, @arg(String) @required name) {
    const user = new User({
      id,
      name,
    });
    users[id] = user;
    return user;
  }
  
  @field(Boolean)
  @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()
github IBM / graphql-schema-bindings / examples / twitter / src / Twitter.ts View on Github external
@field(User)
  @description("Fetch details for a user by screen name.")
  async user(
    @arg(ID)
    @required
    screen_name: string,
    @context context: TwitterContext
  ) {
    const { data } = await context.client.get("/users/show", {
      params: { screen_name }
    });
    return new User(data);
  }

  @field([Tweet])
  @description("Fetch the status timeline for a user by screen name.")
  async user_timeline(
    @arg(ID)
    @required
    screen_name: string,
    @arg(TimelineInput)
    @defaultValue(new TimelineInput())
    input: Partial,
    @context context: TwitterContext
  ): Promise {
    const args = new TimelineInput(input);
    const { data } = await context.client.get(
      "/statuses/user_timeline",
      { params: { screen_name: screen_name, ...args.toParams() } }
    );
    return data.map(makeTweet);
  }
github IBM / graphql-schema-bindings / examples / mutation / index.js View on Github external
* server.
 */
const users = [];

/**
 * Our very simple User class just represents the user ID and the name
 */
@type
class User {
  @field(ID)
  get id() {
    return this.data.id;
  }
  
  @field(String)
  @description('This is the name of the current user')
  get name() {
    return this.data.name;
  }

  constructor(data) {
    this.data = data;
  }
}

/*
 * Now that we've define the user class we'll add a few users to
 * our users array.
 */
users.push(new User({
  id: 0,
  name: 'alice',
github IBM / graphql-schema-bindings / examples / mutation / index.js View on Github external
@description('Get all of the users in the array.')
  users() {
    return users;
  }
}

/**
 * This is our mutation class.  It makes it possible to make changes to our data.
 */
@type
class UserMutation {
  @context
  context;
  
  @field(User)
  @description('Get a user from the array.')
  add(@arg(ID) @required id, @arg(String) @required name) {
    const user = new User({
      id,
      name,
    });
    users[id] = user;
    return user;
  }
  
  @field(Boolean)
  @description('Delete a user from the array.')
  del(@arg(ID) @required id) {
    if (users[id]) {
      delete users[id];
      return true;
    }
github IBM / graphql-schema-bindings / examples / twitter / src / Twitter.ts View on Github external
import { AxiosInstance } from "axios";
import Tweet, { ITweet } from "./types/Tweet";
import SearchInput from "./inputs/SearchInput";
import makeTweet from "./lib/makeTweet";
import TimelineInput from "./inputs/TimelineInput";

export interface TwitterContext {
  client: AxiosInstance;
  twitter: Twitter;
}

@type
@description("This is the base query for Twitter.")
export default class Twitter {
  @field(User)
  @description("Fetch details for a user by screen name.")
  async user(
    @arg(ID)
    @required
    screen_name: string,
    @context context: TwitterContext
  ) {
    const { data } = await context.client.get("/users/show", {
      params: { screen_name }
    });
    return new User(data);
  }

  @field([Tweet])
  @description("Fetch the status timeline for a user by screen name.")
  async user_timeline(
    @arg(ID)
github IBM / graphql-schema-bindings / examples / twitter / src / Twitter.ts View on Github external
description
} from "graphql-schema-bindings";
import User, { IUser } from "./types/User";
import { AxiosInstance } from "axios";
import Tweet, { ITweet } from "./types/Tweet";
import SearchInput from "./inputs/SearchInput";
import makeTweet from "./lib/makeTweet";
import TimelineInput from "./inputs/TimelineInput";

export interface TwitterContext {
  client: AxiosInstance;
  twitter: Twitter;
}

@type
@description("This is the base query for Twitter.")
export default class Twitter {
  @field(User)
  @description("Fetch details for a user by screen name.")
  async user(
    @arg(ID)
    @required
    screen_name: string,
    @context context: TwitterContext
  ) {
    const { data } = await context.client.get("/users/show", {
      params: { screen_name }
    });
    return new User(data);
  }

  @field([Tweet])
github IBM / graphql-schema-bindings / examples / twitter / src / types / User.ts View on Github external
screen_name: string;

  @field()
  name: string;

  @field()
  followers_count: number;

  @field()
  friends_count: number;

  @field()
  statuses_count: number;

  @field(() => [Tweet])
  @description("Fetch the Tweet timeline for this user.")
  async timeline(
    @arg(TimelineInput)
    @defaultValue(new TimelineInput())
    input: Partial
  ): Promise {
    return this.context.twitter.user_timeline(
      this.screen_name,
      input,
      this.context
    );
  }

  /**
   * Create an instance of the User output type.
   * @param data The response data from the API.
   */
github IBM / graphql-schema-bindings / examples / github_users / index.js View on Github external
ID,
  type
} from "graphql-schema-bindings";

/**
 * Our very simple User class just represents the user ID and the name
 */
@type
class User {
  @field(ID)
  get id() {
    return this.data.id;
  }
  
  @field(String)
  @description('This is the name of the current user')
  get name() {
    return this.data.name;
  }

  constructor(data) {
    this.data = data;
  }
}

/**
 * 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) {
github IBM / graphql-schema-bindings / examples / twitter / src / types / Tweet.ts View on Github external
/**
 * Interface for the API response data.
 */
export interface ITweet {
  id_str: string;
  text: string;
  user: IUser;
  created_at: string;
  retweet_count: number;
  favorite_count: number;
  is_quote_status: boolean;
}

@type
@description("A Twitter status update (tweet)")
export default class Tweet {
  data: ITweet;

  @field(ID)
  id: string;

  @field()
  text: string;

  @field()
  created_at: string;

  @field()
  retweet_count: number;

  @field()
github IBM / graphql-schema-bindings / examples / mutation / 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)
  @description('Get a specific user.')
  user(@arg(ID) id) {
    return users[id];
  }
  
  @field([User])
  @description('Get all of the users in the array.')
  users() {
    return users;
  }
}

/**
 * This is our mutation class.  It makes it possible to make changes to our data.
 */
@type
class UserMutation {
  @context
  context;
  
  @field(User)
  @description('Get a user from the array.')
  add(@arg(ID) @required id, @arg(String) @required name) {

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