node_modules.apollo-codegen.src.compiler.visitors.generateOperationId.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-client-maven-plugin Show documentation
Show all versions of apollo-client-maven-plugin Show documentation
Maven plugin for generating graphql clients
import { Operation, Fragment } from '../';
import { collectFragmentsReferenced } from './collectFragmentsReferenced';
import { createHash } from 'crypto';
export function generateOperationId(
operation: Operation,
fragments: { [fragmentName: string]: Fragment },
fragmentsReferenced?: Iterable
) {
if (!fragmentsReferenced) {
fragmentsReferenced = collectFragmentsReferenced(operation.selectionSet, fragments);
}
const sourceWithFragments = [
operation.source,
...Array.from(fragmentsReferenced).map(fragmentName => {
const fragment = fragments[fragmentName];
if (!fragment) {
throw new Error(`Cannot find fragment "${fragmentName}"`);
}
return fragment.source;
})
].join('\n');
const hash = createHash('sha256');
hash.update(sourceWithFragments);
const operationId = hash.digest('hex');
return { operationId, sourceWithFragments };
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy