Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
queryId: string,
options: WatchQueryOptions
): Promise {
const {
variables,
forceFetch = false,
returnPartialData = false,
noFetch = false,
} = options;
const {
queryDoc,
fragmentMap,
} = this.transformQueryDocument(options);
const queryDef = getQueryDefinition(queryDoc);
const queryString = print(queryDoc);
const querySS = {
id: 'ROOT_QUERY',
typeName: 'Query',
selectionSet: queryDef.selectionSet,
} as SelectionSetWithRoot;
// If we don't use diffing, then these will be the same as the original query, other than
// the queryTransformer that could have been applied.
let minimizedQueryString = queryString;
let minimizedQuery = querySS;
let minimizedQueryDoc = queryDoc;
let storeResult: any;
// If this is not a force fetch, we want to diff the query against the
// store before we fetch it from the network interface.
if (!forceFetch) {
const query = gql`
query author {
firstName
lastName
}`;
const expQuery = gql`
query ___composed___author {
firstName
lastName
}`;
const queryDef = getQueryDefinition(query);
const expQueryDefinition = getQueryDefinition(expQuery);
const resultQueryDefinition = addPrefixToQuery('___composed___', queryDef);
assert.deepEqual(print(resultQueryDefinition), print(expQueryDefinition));
});
}
}
fragment authorDetails on Author {
firstName
lastName
}`;
const queryDef = getQueryDefinition(query);
const fragmentDefinition = getFragmentDefinitions(query)[0];
const aliasName = getOperationDefinitionName(queryDef, 2);
const exp = getFragmentDefinitions(gql`
fragment ___authorStuff___requestIndex_2___authorDetails on Author {
___authorStuff___requestIndex_2___fieldIndex_0: firstName
___authorStuff___requestIndex_2___fieldIndex_1: lastName
}`)[0];
const res = applyAliasNameToFragment(fragmentDefinition, aliasName, 0);
assert.equal(print(res), print(exp));
});
query authorStuff {
author {
...authorDetails
}
}`;
const exp = gql`
query {
author {
...___authorStuff___requestIndex_2___authorDetails
}
}`;
const queryDef = getQueryDefinition(doc);
const expDef = getQueryDefinition(exp);
const res = renameFragmentSpreads(queryDef.selectionSet,
'___authorStuff___requestIndex_2');
assert.equal(print(res), print(expDef.selectionSet));
});
public fireResult(id: number) {
const handler = this.handlersById[id];
if (this.mockedSubscriptionsById.hasOwnProperty(id.toString())) {
const subscription = this.mockedSubscriptionsById[id];
if (subscription.results.length === 0) {
throw new Error(`No more mocked subscription responses for the query: ` +
`${print(subscription.request.query)}, variables: ${JSON.stringify(subscription.request.variables)}`);
}
const response = subscription.results.shift();
setTimeout(() => {
handler(response.error, response.result);
}, response.delay ? response.delay : 0);
} else {
throw new Error('Network interface does not have subscription associated with this id.');
}
}
public fireResult(id: number) {
const handler = this.handlersById[id];
if (this.mockedSubscriptionsById.hasOwnProperty(id.toString())) {
const subscription = this.mockedSubscriptionsById[id];
if (subscription.results.length === 0) {
throw new Error(`No more mocked subscription responses for the query: ` +
`${print(subscription.request.query)}, variables: ${JSON.stringify(subscription.request.variables)}`);
}
const response = subscription.results.shift();
setTimeout(() => {
handler(response.error, response.result);
}, response.delay ? response.delay : 0);
} else {
throw new Error('Network interface does not have subscription associated with this id.');
}
}
return mapValues(request, function (val, key) {
return key === 'query' ? printer_1.print(val) : val;
});
}
subscribe: (request, handler) => {
return wsClient.subscribe({
query: print(request.query),
variables: request.variables,
}, handler);
},
unsubscribe: (id) => {
subscribe(request, handler) {
return wsClient.subscribe({
query: print(request.query),
variables: request.variables,
}, handler);
},
unsubscribe(id) {