Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
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
function mockSchema(schema, { mocks } = {}) {
// Clone schema
const clonedSchema = transformSchema(schema, [])
addMockFunctionsToSchema({ schema: clonedSchema, mocks })
return clonedSchema
}
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.
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));
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',
},
namespaceSchema(schema, fieldName, typeName) {
return transformSchema(schema, [
new StripNonQueryTransform(),
new RenameTypes(name => `${typeName}_${name}`),
new NamespaceUnderFieldTransform(typeName, fieldName),
])
}
}
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 }
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
)
]);
}
namespaceSchema (schema, fieldName, typeName) {
return transformSchema(schema, [
new StripNonQueryTransform(),
new RenameTypes(name => `${typeName}_${name}`),
new NamespaceUnderFieldTransform(typeName, fieldName)
])
}
}