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 executableGravitySchema = () => {
const gravityTypeDefs = readFileSync("src/data/gravity.graphql", "utf8")
const gravityLink = createGravityLink()
const schema = makeRemoteExecutableSchema({
schema: gravityTypeDefs,
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
async function run() {
// Step 1: Create local version of the CRUD API
const link = new HttpLink({ uri: process.env.GRAPHQL_ENDPOINT, fetch })
const graphcoolSchema = makeRemoteExecutableSchema({
schema: await introspectSchema(link),
link,
})
// Step 2: Define schema for the new API
const extendTypeDefs = `
extend type Query {
viewer: Viewer!
}
type Viewer {
me: User
topPosts(limit: Int): [Post!]!
}
extend type Mutation {
async function getSchema(endpoint) {
// you can't use relative URLs within Netlify Functions so need a base URL
// process.env.URL is one of many build env variables:
// https://www.netlify.com/docs/continuous-deployment/#build-environment-variables
// Netlify Dev only supports URL and DEPLOY URL for now
const uri = process.env.URL + "/.netlify/functions/" + endpoint;
const link = createHttpLink({ uri, fetch });
const schema = await introspectSchema(link);
const executableSchema = makeRemoteExecutableSchema({ schema, link });
return executableSchema;
}
export default async function createSchema() {
let remoteSchemaContent;
try {
remoteSchemaContent = await introspectSchema(options =>
fetcher({ ...options, ...remoteSchemaOptions })
);
} catch (error) {
console.log(
'GraphQL Mock Server: Cannot introspect schema from',
remoteSchemaOptions.url
);
}
let remoteSchema;
if (remoteSchemaContent) {
remoteSchema = makeRemoteExecutableSchema({
schema: remoteSchemaContent,
fetcher: options => fetcher({ ...options, ...remoteSchemaOptions }),
});
}
return mergeSchemas({
schemas: [remoteSchema, localSchema].filter(Boolean),
resolvers,
});
}
async getRemoteExecutableSchema (uri, headers) {
const http = new HttpLink({ uri, fetch })
const link = setContext(() => ({ headers })).concat(http)
const remoteSchema = await introspectSchema(link)
return makeRemoteExecutableSchema({
schema: remoteSchema,
link
})
}
constructor() {
const endpoint = `${DELIVERY_API_BASE_URL}/spaces/${SPACE_ID}/graphql/alpha?locale=${LOCALE_CODE}`
const link = new HttpLink({
fetch,
uri: endpoint,
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
})
const schema = makeRemoteExecutableSchema({ link, schema: typeDefs })
super({
schema,
})
}
}
if (name === undefined) {
name = `schema${Object.keys(req.supergraph.schemas).length}`
}
if (introspectionSchema === undefined) {
if (!get(`supergraph.${name}.introspection`)) {
introspectionSchema = await introspectSchema(link)
put(`supergraph.${name}.introspection`, introspectionSchema)
} else {
introspectionSchema = get(`supergraph.${name}.introspection`)
}
}
const executableSchema = makeRemoteExecutableSchema({
schema: introspectionSchema,
link
})
req.supergraph.schemas[name] = executableSchema
next()
})
}
async function createRemoteSchema(uri: string) {
const link = new HttpLink({ uri, fetch });
const schema = await introspectSchema(link);
return makeRemoteExecutableSchema({
schema,
link
});
}