You are viewing a single comment's thread from:

RE: graphQL advanced: 고오급 graphQL 테크닉 - Mutation 후 Query를 한반에!

in #kr6 years ago

launchpad가 망할 것을 대비하여 전체 소스를 댓글로 첨부한다.

import { makeExecutableSchema } from 'graphql-tools';

const ballMaxCount = 5;
let ballCount = ballMaxCount;
let scores = [];

const typeDefs = `
  type Score {
    result: Boolean
  }
  type Query {
    getBallCount: Int
    getScores: [ Score ]
  }
  type Mutation {
    submitKick: Query
  }
`;

const resolvers = {
  Query: {
    getBallCount: (root, args, context) => ballCount,
    getScores: ()=> scores
  },
  Mutation: {
    submitKick: (root, args, context) => {
      if (ballCount === 0) {
        ballCount = ballMaxCount;
        scores = [];
      }
      let result = !~~(Math.random()+0.5);
      scores.push( { result } );
      ballCount--;
      return {
        result
      };
    }
  }
};

export const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

export function context(headers, secrets) {
  return {
    headers,
    secrets,
  };
};
Sort:  

아놔 진짜 launchpad 망했네. 나님 선견지명 무엇?

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.027
BTC 60462.58
ETH 2636.31
USDT 1.00
SBD 2.58