UNPKG

ohmygql

Version:

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]

15 lines (13 loc) 475 B
const extractOperation = (query) => { let name; let type; if (typeof query !== "string") { name = query?.definitions?.[0]?.name.value; type = query?.definitions?.[0]?.operation; } else { name = !/(query|mutation)(\s+)?\{/.test(query) && query.match(/\w+(?=(\s+)?(\{|\())(?!(query|mutation))/)?.[0] || void 0; type = query.match(/(query|mutation)(?=(\s+)\w*(\s+)?(\{|\())/)?.[0] || void 0; } return { name, type }; }; export { extractOperation };