How to use the graphql-tools.transformSchema 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 / schema.ts View on Github external
export const executableExchangeSchema = transforms => {
  const exchangeSDL = readFileSync("src/data/exchange.graphql", "utf8")
  const exchangeLink = createExchangeLink()

  const schema = makeRemoteExecutableSchema({
    schema: exchangeSDL,
    link: exchangeLink,
  })

  // Return the new modified schema
  return transformSchema(schema, transforms)
  // Note that changes in this will need to be
}
github artsy / metaphysics / src / lib / stitching / gravity / schema.ts View on Github external
link: gravityLink,
  })

  // Types which come from Gravity which MP already has copies of.
  // In the future, these could get merged into the MP types.
  const removeTypes = [
    "Artist",
    "Artwork",
    "ArtistEdge",
    "ArtworkEdge",
    "ArtworkConnection",
    "ArtistConnection",
  ]

  // Return the new modified schema
  return transformSchema(schema, [
    // Remove types which Metaphysics handles better
    new FilterTypes(type => {
      return !removeTypes.includes(type.name)
    }),
    // So, we cannot remove all of the types from a schema is a lesson I have
    // learned in creating these transformations. This means that there has to
    // be at least one type still inside the Schema (excluding the Mutation or
    // the Query)
    // When Partner was removed, we'd see this error
    // https://github.com/graphcool/graphql-import/issues/73
    // but I don't think we're exhibiting the same bug.
    new RenameTypes(name => {
      if (name === "Partner") {
        return "DoNotUseThisPartner"
      }
      return name
github smooth-code / fraql / src / mock.js View on Github external
function mockSchema(schema, { mocks } = {}) {
  // Clone schema
  const clonedSchema = transformSchema(schema, [])
  addMockFunctionsToSchema({ schema: clonedSchema, mocks })
  return clonedSchema
}
github artsy / metaphysics / src / schema / v2 / v2 / index.ts View on Github external
export const transformToV2 = (
  schema: GraphQLSchema,
  options: Partial = {}
): GraphQLSchema => {
  const opt = {
    allowedGravityTypesWithNullableIDField: KnownGravityTypesWithNullableIDFields,
    allowedNonGravityTypesWithNullableIDField: KnownNonGravityTypesWithNullableIDFields,
    stitchedTypePrefixes: StitchedTypePrefixes,
    filterTypes: FilterTypeNames,
    ...options,
  }
  const allowedTypesWithNullableIDField = [
    ...opt.allowedGravityTypesWithNullableIDField,
    ...opt.allowedNonGravityTypesWithNullableIDField,
  ]
  return transformSchema(schema, [
    new FilterTypes(type => {
      return !opt.filterTypes.includes(type.name)
    }),
    // Filter out `id` fields from Exchange types
    new FilterFields(
      (type, field) =>
        !type.name.startsWith("Commerce") ||
        // TODO: These two exchange types are only meant for stitching and
        //       should simply be filtered out after stitching, but I don't want
        //       to make such a large sweeping change right now.
        type.name === "CommercePartner" ||
        type.name === "CommerceUser" ||
        field.name !== "id"
    ),
    new RenameFields((type, field) => {
      // Only rename ID fields on stitched services.
github slicknode / slicknode / src / validation / validateSchema.ts View on Github external
function transformRemoteSchema(schema: string, namespace: string | null): string {
  let transformedSchema = buildSchema(schema);
  transformedSchema = transformSchema(transformedSchema, [
    new RenameTypes(
      (name) => namespace ? `${namespace}_${name}` : name,
    ),
    new RenameRootFields(
      ((operation, name) => namespace ? `${namespace}_${name}` : name),
    ),
  ]);
  const rootTypeNames: string[] = [];
  if (transformedSchema.getMutationType()) {
    rootTypeNames.push(transformedSchema.getMutationType()!.name);
  }
  if (transformedSchema.getQueryType()) {
    rootTypeNames.push(transformedSchema.getQueryType()!.name);
  }
  // Once subscriptions are supported, do the same here...
  let transformedSchemaDoc = parse(printSchema(transformedSchema));
github apollo-model / apollo-model / packages / schema-filter / dev-server / index.js View on Github external
resolvers,
  },
]);

let filterFields = FilterFields(
  (type, field) => {
    return !/^.*\.id$/.test(`${type.name}.${field.name}`);
  },
  (type, field) => {
    if (/.*\.id/.test(`${type.name}.${field.name}`)) {
      return () => null;
    }
  }
);

schema = transformSchema(schema, [filterFields]);

const server = new ApolloServer({
  schema,
});

server.listen({ port: 4005 }).then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

const users = [
  {
    id: '1',
    name: 'Ada Lovelace',
    birthDate: '1815-12-10',
    username: '@ada',
  },
github jakedohm / gridsome-source-craftql / index.js View on Github external
namespaceSchema(schema, fieldName, typeName) {
    return transformSchema(schema, [
      new StripNonQueryTransform(),
      new RenameTypes(name => `${typeName}_${name}`),
      new NamespaceUnderFieldTransform(typeName, fieldName),
    ])
  }
}
github strvcom / dep-manager-web / src / api / schema / github / index.ts View on Github external
import { transformSchema } from 'graphql-tools'

import { schema as originalSchema } from './schema'
import { transform as transformConnections } from './transforms/connections'

const schema = transformSchema(originalSchema, [transformConnections])

export { schema }
github nilshartmann / graphql-examples / schema-stitching / schema-stitcher / src / Stitcher.ts View on Github external
function renameSystemInfo(schema: GraphQLSchema, systemName: String) {
  return transformSchema(schema, [
    new RenameTypes((name: string) => (name === "ProcessInfo" ? `${systemName}Status` : undefined)),
    new RenameRootFields(
      (_operation: string, name: string) =>
        name === "ping" ? `${systemName.substring(0, 1).toLowerCase()}${systemName.substring(1)}Status` : name
    )
  ]);
}
github gridsome / gridsome / packages / source-graphql / index.js View on Github external
namespaceSchema (schema, fieldName, typeName) {
    return transformSchema(schema, [
      new StripNonQueryTransform(),
      new RenameTypes(name => `${typeName}_${name}`),
      new NamespaceUnderFieldTransform(typeName, fieldName)
    ])
  }
}