Skip to content

Commit

Permalink
Merge branch '1' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Apr 17, 2023
2 parents 05b4163 + 38393e1 commit af1b086
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 14 deletions.
12 changes: 6 additions & 6 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defaultTag } from './tags';
import { getSingularName, getFields, getFragments } from './helpers';
import { getSingularName, getCreateMutationType, getFields, getFragments } from './helpers';

const buildCreateMutation = (tag = defaultTag) => (
tag`mutation Create${getSingularName}(
$Input:${getSingularName}CreateInputType!
$input:${getCreateMutationType}!
) {
create${getSingularName}(
Input: $Input
input: $input
) {
${getFields}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { defaultTag } from './tags';
import { getSingularName, getVariables, getParams, getFields, getFragments } from './helpers';
import { getSingularName, getUpdateMutationType, getVariables, getParams, getFields, getFragments } from './helpers';

const buildUpdateMutation = (tag = defaultTag) => (
tag`mutation Update${getSingularName}(
$Input:${getSingularName}UpdateInputType!
$input:${getUpdateMutationType}!
${getVariables}
) {
update${getSingularName}(
Input: $Input
input: $input
${getParams}
) {
${getFields}
Expand Down
12 changes: 12 additions & 0 deletions client/src/lib/dependency-injection/graphql/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ export const getFragments = ({ availableFragments, fragments = [] }) => (
: capturedFragments
), '')
);

function isLegacy() {
return !!document.body.getAttribute('data-graphql-legacy');
}

export const getCreateMutationType = ({ singularName }) => (
isLegacy() ? `${singularName}CreateInputType` : `Create${singularName}Input`
);

export const getUpdateMutationType = ({ singularName }) => (
isLegacy() ? `${singularName}UpdateInputType` : `Update${singularName}Input`
);
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,42 @@ describe('Dynamic graphql injection', () => {

expect(AST.kind).toBe('Document');
const compiledQuery = AST.loc.source.body;
expect(compiledQuery).toMatch(/\s*mutation\s+UpdateDino\(\s*\$Input:\s*DinoUpdateInputType!\s*\)\s+{\s+updateDino\(\s*Input:\s*\$Input\s*\)\s+{\s+Teeth Plates\s+}\s+}\s*$/);
expect(compiledQuery).toMatch(/\s*mutation\s+UpdateDino\(\s*\$input:\s*UpdateDinoInput!\s*\)\s+{\s+updateDino\(\s*input:\s*\$input\s*\)\s+{\s+Teeth Plates\s+}\s+}\s*$/);
});

it('Allows customisation of graphql3 UPDATE queries', () => {
document.body.setAttribute('data-graphql-legacy', 1);

const { UPDATE } = graphqlTemplates;
const query = {
apolloConfig: {
},
templateName: UPDATE,
singularName: 'Dino',
pagination: false,
params: {},
fields: [
'Teeth',
],
};

Injector.test.register('MyTestUpdateQuery', query);
Injector.transform(
'test-transform',
(updater) => {
updater.test('MyTestUpdateQuery', (manager) => {
manager.addField('Plates');
});
}
);
Injector.load();

const AST = fetchManager('MyTestUpdateQuery').getGraphqlAST();

expect(AST.kind).toBe('Document');
const compiledQuery = AST.loc.source.body;
expect(compiledQuery).toMatch(/\s*mutation\s+UpdateDino\(\s*\$input:\s*DinoUpdateInputType!\s*\)\s+{\s+updateDino\(\s*input:\s*\$input\s*\)\s+{\s+Teeth Plates\s+}\s+}\s*$/);
document.body.removeAttribute('data-graphql-legacy');
});

it('Allows customisation of DELETE queries', () => {
Expand Down Expand Up @@ -224,7 +259,42 @@ describe('Dynamic graphql injection', () => {

expect(AST.kind).toBe('Document');
const compiledQuery = AST.loc.source.body;
expect(compiledQuery).toMatch(/\s*mutation\s+CreateDino\(\s*\$Input:\s*DinoCreateInputType!\s*\)\s+{\s+createDino\(\s*Input:\s*\$Input\s*\)\s+{\s+Club Claws\s+}\s+}\s*$/);
expect(compiledQuery).toMatch(/\s*mutation\s+CreateDino\(\s*\$input:\s*CreateDinoInput!\s*\)\s+{\s+createDino\(\s*input:\s*\$input\s*\)\s+{\s+Club Claws\s+}\s+}\s*$/);
});

it('Allows customisation of graphql3 CREATE queries', () => {
document.body.setAttribute('data-graphql-legacy', 1);

const { CREATE } = graphqlTemplates;
const query = {
apolloConfig: {
},
templateName: CREATE,
singularName: 'Dino',
pagination: false,
params: {},
fields: [
'Club',
],
};

Injector.test.register('MyTestCreateQuery', query);
Injector.transform(
'test-transform',
(updater) => {
updater.test('MyTestCreateQuery', (manager) => {
manager.addField('Claws');
});
}
);
Injector.load();

const AST = fetchManager('MyTestCreateQuery').getGraphqlAST();

expect(AST.kind).toBe('Document');
const compiledQuery = AST.loc.source.body;
expect(compiledQuery).toMatch(/\s*mutation\s+CreateDino\(\s*\$input:\s*DinoCreateInputType!\s*\)\s+{\s+createDino\(\s*input:\s*\$input\s*\)\s+{\s+Club Claws\s+}\s+}\s*$/);
document.body.removeAttribute('data-graphql-legacy');
});
});

0 comments on commit af1b086

Please sign in to comment.