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

You are viewing a single comment's thread from:

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

in kr •  7 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,
  };
};
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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

  ·  6 years ago Reveal Comment