How to use the graphql-schema-bindings.field 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 / twitter / src / types / Tweet.ts View on Github external
@field()
  text: string;

  @field()
  created_at: string;

  @field()
  retweet_count: number;

  @field()
  favorite_count: number;

  // Due to the circular reference between Tweet and User
  // the resolution of User needs to be deferred (via thunk function).
  @field(() => User)
  get user(): User {
    return new User(this.data.user);
  }

  /**
   * Create an instance of the Tweet output type.
   * @param data Tweet data from the API.
   */
  constructor(data: ITweet) {
    this.data = data;
    this.id = data.id_str;
    this.text = data.text;
    this.created_at = data.created_at;
    this.retweet_count = data.retweet_count;
    this.favorite_count = data.favorite_count;
  }
github IBM / graphql-schema-bindings / examples / xkcd / index.js View on Github external
@type
class XKCDQuery {
  @field(Comic)
  async comic(@arg(ID) id) {
    const url = id ? `/${id}` : "";
    const { data } = await axios.get(`https://xkcd.com${url}/info.0.json`);
    return new Comic(data);
  }

  @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 / mutation / index.js View on Github external
@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) {
    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 / github_users / index.js View on Github external
import {
  arg,
  context,
  createSchema,
  description,
  field,
  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;
  }
}

/**
github IBM / graphql-schema-bindings / examples / xkcd / index.js View on Github external
@field(String)
  get transcript() {
    return this.data.transcript || this.data.alt;
  }

  @field(String)
  get date() {
    return new Date(
      this.data.year,
      this.data.month,
      this.data.day
    ).toLocaleDateString();
  }

  @field(String)
  get link() {
    return `https://xkcd.com/${this.number}`;
  }

  @field(Comic)
  async previous() {
    return this.context.comic(this.number - 1);
  }

  @field(Comic)
  async next() {
    return this.context.comic(this.number + 1);
  }

  constructor(data) {
    this.data = data;
github IBM / graphql-schema-bindings / examples / xkcd / index.js View on Github external
@field(String)
  get title() {
    return this.data.title;
  }

  @field(String)
  get image() {
    return this.data.img;
  }

  @field(String)
  get transcript() {
    return this.data.transcript || this.data.alt;
  }

  @field(String)
  get date() {
    return new Date(
      this.data.year,
      this.data.month,
      this.data.day
    ).toLocaleDateString();
  }

  @field(String)
  get link() {
    return `https://xkcd.com/${this.number}`;
  }

  @field(Comic)
  async previous() {
    return this.context.comic(this.number - 1);
github IBM / graphql-schema-bindings / examples / xkcd / index.js View on Github external
@field(String)
  get date() {
    return new Date(
      this.data.year,
      this.data.month,
      this.data.day
    ).toLocaleDateString();
  }

  @field(String)
  get link() {
    return `https://xkcd.com/${this.number}`;
  }

  @field(Comic)
  async previous() {
    return this.context.comic(this.number - 1);
  }

  @field(Comic)
  async next() {
    return this.context.comic(this.number + 1);
  }

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

@type
class XKCDQuery {
github IBM / graphql-schema-bindings / examples / mutation / index.js View on Github external
name: 'carol',
}));


/**
 * 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.')
github IBM / graphql-schema-bindings / examples / xkcd / index.js View on Github external
this.data.month,
      this.data.day
    ).toLocaleDateString();
  }

  @field(String)
  get link() {
    return `https://xkcd.com/${this.number}`;
  }

  @field(Comic)
  async previous() {
    return this.context.comic(this.number - 1);
  }

  @field(Comic)
  async next() {
    return this.context.comic(this.number + 1);
  }

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

@type
class XKCDQuery {
  @field(Comic)
  async comic(@arg(ID) id) {
    const url = id ? `/${id}` : "";
    const { data } = await axios.get(`https://xkcd.com${url}/info.0.json`);
    return new Comic(data);
github IBM / graphql-schema-bindings / examples / github_users / index.js View on Github external
field,
  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)

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