本文整理汇总了TypeScript中graphql-tools.makeExecutableSchema函数的典型用法代码示例。如果您正苦于以下问题:TypeScript makeExecutableSchema函数的具体用法?TypeScript makeExecutableSchema怎么用?TypeScript makeExecutableSchema使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了makeExecutableSchema函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: makeExecutableSchema
export const initServer = (libs: AppBackendLibs, config: Config) => {
const schema = makeExecutableSchema({
resolvers: [
createAuthenticationsResolvers(libs) as IResolvers,
createEsValueResolvers() as IResolvers,
createEventsResolvers(libs) as IResolvers,
createHostsResolvers(libs) as IResolvers,
createIpDetailsResolvers(libs) as IResolvers,
createKpiNetworkResolvers(libs) as IResolvers,
createNoteResolvers(libs) as IResolvers,
createPinnedEventResolvers(libs) as IResolvers,
createSourcesResolvers(libs) as IResolvers,
createScalarToStringArrayValueResolvers() as IResolvers,
createOverviewResolvers(libs) as IResolvers,
createNetworkResolvers(libs) as IResolvers,
createScalarDateResolvers() as IResolvers,
createScalarToDateArrayValueResolvers() as IResolvers,
createScalarToBooleanArrayValueResolvers() as IResolvers,
createScalarToNumberArrayValueResolvers() as IResolvers,
createSourcesResolvers(libs) as IResolvers,
createSourceStatusResolvers(libs) as IResolvers,
createTimelineResolvers(libs) as IResolvers,
createUncommonProcessesResolvers(libs) as IResolvers,
createWhoAmIResolvers() as IResolvers,
createKpiHostsResolvers(libs) as IResolvers,
],
typeDefs: schemas,
});
libs.framework.registerGraphQLEndpoint('/api/siem/graphql', schema);
};
示例2: marbles
marbles(async m => {
const resolverConfig = makeResolverConfig(m);
resolverConfig.fetchNodesNetwork = jest
.fn(resolverConfig.fetchNodesNetwork)
.mockReturnValue(of({ response: makeFakeNodesNetworkResponse() }));
const nodesSchema = makeExecutableSchema({
typeDefs: schemas,
resolvers: resolvers(resolverConfig)
});
const query = gql`
query {
networks(privateIPs: $privateIPs) {
public_ips
}
}
`;
const output$ = graphqlObservable(query, nodesSchema, {
privateIPs: ["13.0.6.125", "13.0.6.96", "13.0.1.42"]
}).pipe(take(1));
await output$.toPromise();
expect(resolverConfig.fetchNodesNetwork).toHaveBeenCalledTimes(1);
})
示例3: makeExecutableSchemaWithCacheControlSupport
export function makeExecutableSchemaWithCacheControlSupport(
options: FirstArg<typeof makeExecutableSchema> & { typeDefs: string },
) {
return makeExecutableSchema({
...options,
typeDefs: augmentTypeDefsWithCacheControlSupport(options.typeDefs),
});
}
示例4: marbles
marbles(m => {
const fetchServicePlans = (_service: string) =>
m.cold("j|", {
j: {
code: 200,
message: "ok",
response: ["plan-01"]
}
});
const fetchServicePlanDetail = (_service: string, _planName: string) =>
m.cold("--j|", {
j: {
code: 200,
message: "ok",
response: makeFakePlanResponse()
}
});
const serviceSchema = makeExecutableSchema({
typeDefs: schemas,
resolvers: resolvers({
fetchServicePlans,
fetchServicePlanDetail,
pollingInterval: m.time("--|")
})
});
const query = gql`
query {
service(id: $serviceId) {
id
plans {
name
}
}
}
`;
const queryResult$ = graphqlObservable(query, serviceSchema, {
serviceId: "test"
});
const expected$ = m.cold("--x-x-(x|)", {
x: {
data: {
service: {
id: "test",
plans: [
{
name: "plan-01"
}
]
}
}
}
});
m.expect(queryResult$.pipe(take(3))).toBeObservable(expected$);
})
示例5: test
test('trace construction', async () => {
const typeDefs = `
type User {
id: Int
name: String
posts(limit: Int): [Post]
}
type Post {
id: Int
title: String
views: Int
author: User
}
type Query {
aString: String
aBoolean: Boolean
anInt: Int
author(id: Int): User
topPosts(limit: Int): [Post]
}
`;
const query = `
query q {
author(id: 5) {
name
posts(limit: 2) {
id
}
}
aBoolean
}
`;
const schema = makeExecutableSchema({ typeDefs });
addMockFunctionsToSchema({ schema });
enableGraphQLExtensions(schema);
const traces: Array<any> = [];
function addTrace(signature: string, operationName: string, trace: Trace) {
traces.push({ signature, operationName, trace });
}
const reportingExtension = new EngineReportingExtension({}, addTrace);
const stack = new GraphQLExtensionStack([reportingExtension]);
const requestDidEnd = stack.requestDidStart({
request: new Request('http://localhost:123/foo') as any,
queryString: query,
});
await graphql({
schema,
source: query,
contextValue: { _extensionStack: stack },
});
requestDidEnd();
// XXX actually write some tests
});
示例6: makeExecutableSchema
export const initUptimeServer = (libs: UMServerLibs) => {
restApiRoutes.forEach(route => libs.framework.registerRoute(createRouteWithAuth(libs, route)));
const graphQLSchema = makeExecutableSchema({
resolvers: resolvers.map(createResolversFn => createResolversFn(libs)),
typeDefs,
});
libs.framework.registerGraphQLEndpoint(DEFAULT_GRAPHQL_PATH, graphQLSchema);
};
示例7: getSchema
export default async function getSchema() {
const files = await globby('typeDefs/*.graphql', { cwd: __dirname })
const typeDefs = await Promise.all(
files.map(async file => {
const buffer = await readFileAsync(path.join(__dirname, file))
return buffer.toString()
})
)
return makeExecutableSchema({ typeDefs, resolvers })
}
示例8: require
folders.forEach(folder => {
const { resolvers } = require(`../modules/${folder}/resolvers`);
const typeDefs = importSchema(
path.join(__dirname, `../modules/${folder}/schema.graphql`)
);
// Make a schema for each folder in module and store the schema for each folder
// in the schema array
schemas.push(
makeExecutableSchema({ resolvers, typeDefs })
);
})