How to use the graphql-tools/dist/stitching/schemaRecreation.createResolveType function in graphql-tools

To help you get started, we’ve selected a few graphql-tools 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 artsy / metaphysics / src / lib / stitching / exchange / transformers / replaceCommerceDateTimeType.ts View on Github external
private transformFields(type: TypeWithSelectableFields) {
    let madeChanges = false
    const fields = type.getFields()
    const newFields: GraphQLFieldConfigMap = {}
    const resolveType = createResolveType((_name, type) => {
      if (
        isNamedType(type) &&
        (type.name === "CommerceDateTime" ||
          (isWrappingType(type) &&
            type.ofType &&
            type.ofType.name === "CommerceDateTime"))
      ) {
        return dateField.type
      }
      return type
    })

    Object.entries(fields).forEach(([fieldName, fieldDefinition]) => {
      const fieldConfig = fieldToFieldConfig(fieldDefinition, resolveType, true)
      const type = fieldDefinition.type
      // If it's not a type we want to replace, just skip it
github apollo-model / apollo-model / packages / schema-filter / src / index.js View on Github external
for (let key in object) {
    let predicateValue = predicate(object[key]);
    if (!result[predicateValue]) result[predicateValue] = {};
    result[predicateValue][key] = object[key];
  }
  return result;
};

export const reduceValues = values => {
  return values.reduce((state, item) => {
    state[item.name] = R.omit(['deprecationReason', 'isDeprecated'], item);
    return state;
  }, {});
};

const resolveType = createResolveType((typeName, type) => {
  return type;
});

export default (filterFields, defaultFields) => {
  let typeMap = {};
  const getType = typeName => typeMap[typeName];

  let defaults = DefaultFields();

  return {
    transformRequest(request) {
      const typeStack = [];

      let newDocument = visit(request.document, {
        [Kind.OPERATION_DEFINITION]: {
          enter: node => {
github artsy / metaphysics / src / schema / v2 / transforms / RenameArguments.ts View on Github external
private transformFields(
    type: GraphQLObjectType | GraphQLInterfaceType
  ) {
    const fields = type.getFields()
    const newFields: GraphQLFieldConfigMap = {}
    const resolveType = createResolveType((_name, type) => type)

    Object.keys(fields).forEach(fieldName => {
      const field = fields[fieldName]
      const newField = fieldToFieldConfig(field, resolveType, true)
      const newFieldArgs = newField.args
      if (newFieldArgs) {
        field.args.forEach(arg => {
          const oldName = arg.name
          const newName = this.renamer(field, arg)
          if (newName) {
            newFieldArgs[newName] = newFieldArgs[oldName]
            delete newFieldArgs[oldName]
            const originalResolver = newField.resolve
            newField.resolve = (source, args, context, info) => {
              const newArgs = { ...args, [oldName]: args[newName] }
              delete newArgs[newName]
github artsy / metaphysics / src / schema / v2 / transforms / FilterFields.ts View on Github external
private transformFields(
    type: GraphQLObjectType | GraphQLInterfaceType
  ) {
    let madeChanges = false
    const fields = type.getFields()
    const newFields: GraphQLFieldConfigMap = {}
    const resolveType = createResolveType((_name, type) => type)
    Object.keys(fields).forEach(fieldName => {
      const field = fields[fieldName]
      if (this.filter(type, field)) {
        newFields[fieldName] = fieldToFieldConfig(field, resolveType, true)
      } else {
        madeChanges = true
      }
    })
    return madeChanges ? newFields : undefined
  }
}
github artsy / metaphysics / src / schema / v2 / RemoveDeprecatedFields.ts View on Github external
private transformFields(
    type: GraphQLObjectType | GraphQLInterfaceType
  ) {
    const fields = type.getFields()
    const newFields: GraphQLFieldConfigMap = {}
    const resolveType = createResolveType((_name, type) => type)
    Object.keys(fields).forEach(fieldName => {
      const field = fields[fieldName]
      if (
        !field.deprecationReason ||
        (this.options.filter(type, field) &&
          !shouldBeRemoved({
            inVersion: this.options.fromVersion,
            deprecationReason: field.deprecationReason,
            typeName: type.name,
            fieldName,
          }))
      ) {
        newFields[fieldName] = fieldToFieldConfig(field, resolveType, true)
      }
    })
    return newFields
github artsy / metaphysics / src / schema / v2 / RenameFields.ts View on Github external
private transformFields(type: TypeWithSelectableFields) {
    let madeChanges = false
    const fields = type.getFields()
    const newFields: GraphQLFieldConfigMap = {}
    const resolveType = createResolveType((_name, type) => type)

    Object.keys(fields).forEach(oldName => {
      /**
       * If the key already exists, it means another field got renamed to this
       * `oldName` and we should not override it with an old implementation.
       * I.e. the old implementation got replaced by the newly renamed one.
       */
      if (!this.changedFields[fieldKey(type, oldName)]) {
        const field = fields[oldName]
        const newField = fieldToFieldConfig(field, resolveType, true)
        const newName = this.renamer(type, field)
        if (newName) {
          madeChanges = true
          newFields[newName] = {
            ...newField,
            resolve: source => source[oldName],