Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public request(operation: Operation, forward?: NextLink): Observable {
const {query} = operation;
const isRtdbQuery = hasDirectives(['rtdbSub'], query);
if (!isRtdbQuery && forward) {
return forward(operation);
}
const queryWithTypename = addTypenameToDocument(query);
const mainDefinition = getMainDefinition(query);
const context: ResolverContext = {
database: this.database,
findType: fieldDirectives =>
(fieldDirectives.rtdbSub && fieldDirectives.rtdbSub.type) ||
(fieldDirectives.rtdbQuery && fieldDirectives.rtdbQuery.type),
exportVal: {}
};
// Subscription operations must have exactly one root field.
const onlyRootField: FieldNode = mainDefinition.selectionSet.selections[0] as FieldNode;
// get directives
const directives = getDirectiveInfoFromField(onlyRootField, operation.variables);
const rtdbDirectives: SubDirectiveArgs = directives.rtdbSub as any;
public request (operation: Operation, forward?: NextLink) {
const isRestQuery = hasDirectives(['rest'], operation.query)
if (!isRestQuery && forward) return forward(operation)
const nonRestQuery = removeRestDirective(operation.query)
const typeNamedQuery = addTypenameToDocument(operation.query)
const observable =
nonRestQuery && forward
? // tslint:disable-next-line:prefer-object-spread
forward(Object.assign(operation, { query: nonRestQuery }))
: Observable.of({ data: {} })
return observable.flatMap(
({ data, ...rest }) =>
new Observable(subscriber => {
graphql(
resolver,
typeNamedQuery,
data,
this.resolverMap,
operation.variables
)
.then(resolvedData => {
public _getSubscriptions(query: DocumentNode, variables?: any) {
if (!query) {
return this.subscriptionQueries;
}
const queryStr = print(addTypenameToDocument(query));
const key = JSON.stringify({
query: queryStr,
variables: variables || {}
});
const subscriptions = (!variables ? this.subscriptionQueries[queryStr] : this.subscriptions[key]) || [];
const handlers = this.handlers;
return subscriptions.map((subId: number) => {
const res = {
next(value: any) {
return handlers[subId].handler.next(value);
},
error(errorValue: any) {
return handlers[subId].handler.error(errorValue);
}
function requestToKey(request: GraphQLRequest, addTypename: Boolean): string {
const queryString =
request.query &&
print(addTypename ? addTypenameToDocument(request.query) : request.query);
const requestKey = { query: queryString };
return JSON.stringify(requestKey);
}
function requestToKey(request, addTypename) {
var queryString = request.query &&
print(addTypename ? addTypenameToDocument(request.query) : request.query);
var requestKey = { query: queryString };
return JSON.stringify(requestKey);
}
var MockLink = (function (_super) {
if (resolverMap) {
const resolve = resolverMap[fieldName];
if (resolve) {
return resolve(rootValue, args, context, info);
}
}
const fieldValue = rootValue[info.resultKey];
if (fieldValue !== undefined) {
return fieldValue;
}
return null;
};
const queryWithTypename = addTypenameToDocument(query);
const connectors = multiConnectors
? mapValues(multiConnectors, connector => {
return new DataLoaderConnector({keys: schemaKeys, connector});
})
: mapValues(schema, (value, key) => {
return new DataLoaderConnector({keys: schemaKeys, connector: singleConnector});
});
return new Observable(observer => {
graphql(
graphqlResolver,
queryWithTypename,
{},
{document: queryWithTypename, connectors},
operation.variables
)
const makeAuthorMock = ({ count, withImages, slug, delay = 1000 }) => ({
delay,
request: {
query: addTypenameToDocument(authorProfileQuery),
variables: {
slug
}
},
result: {
data: {
author: {
...makeAuthor({ count, withImages })
}
}
}
});
import { addTypenameToDocument } from "apollo-utilities";
import authorArticlesNoImagesQuery from "./author_articles_no_images.graphql";
export default addTypenameToDocument(authorArticlesNoImagesQuery);
export const propsToVariables = ({
longSummaryLength,
pageSize,
page,
shortSummaryLength,
slug
}) => ({
first: pageSize,
longSummaryLength,
shortSummaryLength,
skip: pageSize * (page - 1),
slug
});
import { addTypenameToDocument } from "apollo-utilities";
import getTokenisedArticleUrl from "./get_tokenised_article_url.graphql";
export default addTypenameToDocument(getTokenisedArticleUrl);
import { addTypenameToDocument } from "apollo-utilities";
import authorArticlesWithImages from "./author_articles_with_images.graphql";
export default addTypenameToDocument(authorArticlesWithImages);
export const propsToVariables = ({
slug,
pageSize,
page,
articleImageRatio = "3:2"
}) => ({
first: pageSize,
imageRatio: articleImageRatio,
skip: pageSize * (page - 1),
slug
});