<commit_before>var { graphql, buildSchema, defaultFieldResolver, GraphQLFieldResolver } = require('graphql');
 
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
    tasks: Tasks!
  }

  type Tasks {
    tasks: [Task!]!
    nextCursor: ID
  }
  type Task {
    id: ID
    title: String
    done: Boolean
    titleSize: Int
  }
`);

const tasks = [
  { id: '1', title: 'foo' , done: false },
  { id: '2', title: 'bar' , done: false },
  { id: '3', title: 'baz' , done: true  },
  { id: '4', title: 'hoge', done: true  },
];
 
// The root provides a resolver function for each API endpoint
var root = {
  hello: 'Hello world!',
  tasks: () => {
    return ({
      tasks,
      nextCursor: '5',
    });
  },
};
 
// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
  console.log(response);
});

const source = `
  {
    tasks {
      tasks {
        id
        title
        done
        titleSize
      }
      nextCursor
    }
  }
`;

const resolvers = {
  Task: {
    titleSize: (source, args, contextValue, info) => source.title.length,
  },
};

const fieldResolver = (...args) => {
  const result = defaultFieldResolver(...args);
  if (result !== undefined) {
    return result;
  }
  const info = args[3];
  const property = resolvers[info.path.typename][info.fieldName];
  if (typeof property === 'function') {
    return property(...args);
  }
  return property;
};

graphql({ schema, source, rootValue: root, fieldResolver }).then((response) => {
  console.log(JSON.stringify(response.data));
});
<commit_msg>mutation<commit_after>var { graphql, buildSchema, defaultFieldResolver, GraphQLFieldResolver } = require('graphql');
 
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
    tasks: Tasks!
  }
  type Mutation {
    addTask(title: String): Task
  }

  type Tasks {
    tasks: [Task!]!
    nextCursor: ID
  }
  type Task {
    id: ID
    title: String
    done: Boolean
    titleSize: Int
  }
`);

const idGenerator = (() => {
  let value = 0;
  return () => {
    value++;
    return value.toString();
  };
})();
const tasks = [
  { id: idGenerator(), title: 'foo' , done: false },
  { id: idGenerator(), title: 'bar' , done: false },
  { id: idGenerator(), title: 'baz' , done: true  },
  { id: idGenerator(), title: 'hoge', done: true  },
];
 
// The root provides a resolver function for each API endpoint
var root = {
  hello: 'Hello world!',
  tasks: () => {
    return ({
      tasks,
      nextCursor: (tasks.length + 1).toString(),
    });
  },
  addTask: ({ title }) => {
    const task = { id: idGenerator(), title, done: false };
    tasks.push(task);
    return task;
  },
};
 
// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
  console.log(response);
});

const source = `
  {
    tasks {
      tasks {
        id
        title
        done
        titleSize
      }
      nextCursor
    }
  }
`;

const resolvers = {
  Task: {
    titleSize: (source, args, contextValue, info) => source.title.length,
  },
};

const fieldResolver = (...args) => {
  const result = defaultFieldResolver(...args);
  if (result !== undefined) {
    return result;
  }
  const info = args[3];
  const property = resolvers[info.path.typename][info.fieldName];
  if (typeof property === 'function') {
    return property(...args);
  }
  return property;
};

graphql({ schema, source, rootValue: root, fieldResolver }).then((response) => {
  console.log(JSON.stringify(response.data));
});

graphql({ schema, source: `
  mutation AddTask($title: String!) {
    addTask(title: $title) {
      id
      title
      done
    }
  }
`, rootValue: root, fieldResolver, variableValues: {
  title: 'helloworld',
} }).then((response) => {
  console.log(response);
});

graphql({ schema, source, rootValue: root, fieldResolver }).then((response) => {
  console.log(JSON.stringify(response.data));
});

{'fraction_non_alphanumeric': 0.16210889381621088, 'fraction_numerical': 0.0022172949002217295, 'mean_word_length': 2.8446969696969697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2461228', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1307, 'n_words': 352}