-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
2,204 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { DocumentNode, print } from 'graphql'; | ||
import gql from 'graphql-tag'; | ||
import { Project, ProjectSource, ValidationResult } from '../../core-exports'; | ||
import { ModuleSelectionOptions } from '../../src/project/select-modules-in-sources'; | ||
import { | ||
expectSingleCompatibilityIssueToInclude, | ||
expectToBeValid, | ||
} from './implementation/validation-utils'; | ||
|
||
describe('checkCompatibility', () => { | ||
it('accepts a simple case', () => { | ||
const result = run( | ||
gql` | ||
type Test @rootEntity @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity { | ||
field: String | ||
} | ||
`, | ||
['module1'], | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('rejects if a type is missing', () => { | ||
const result = run( | ||
gql` | ||
type Test @rootEntity @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type WrongTypeName @rootEntity { | ||
field: String | ||
} | ||
`, | ||
['module1'], | ||
); | ||
expectSingleCompatibilityIssueToInclude(result, 'Type "Test" is missing.'); | ||
}); | ||
|
||
it('rejects if a field is missing', () => { | ||
const result = run( | ||
gql` | ||
type Test @rootEntity @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity { | ||
wrongFieldName: String | ||
} | ||
`, | ||
['module1'], | ||
); | ||
expectSingleCompatibilityIssueToInclude(result, 'Field "Test.field" is missing.'); | ||
}); | ||
|
||
it('rejects if a field has the wrong type', () => { | ||
const result = run( | ||
gql` | ||
type Test @rootEntity @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity { | ||
field: Int | ||
} | ||
`, | ||
['module1'], | ||
); | ||
expectSingleCompatibilityIssueToInclude( | ||
result, | ||
'Field "Test.field" needs to be of type "String".', | ||
); | ||
}); | ||
|
||
it('rejects if a field should be a list', () => { | ||
const result = run( | ||
gql` | ||
type Test @rootEntity @modules(in: "module1") { | ||
field: [String] @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity { | ||
field: String | ||
} | ||
`, | ||
['module1'], | ||
); | ||
expectSingleCompatibilityIssueToInclude(result, 'Field "Test.field" needs to be a list.'); | ||
}); | ||
|
||
it('rejects if a field wrongly is a list', () => { | ||
const result = run( | ||
gql` | ||
type Test @rootEntity @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity { | ||
field: [String] | ||
} | ||
`, | ||
['module1'], | ||
); | ||
expectSingleCompatibilityIssueToInclude(result, 'Field "Test.field" should not be a list.'); | ||
}); | ||
}); | ||
|
||
function run( | ||
baselineDoc: DocumentNode, | ||
docToCheck: DocumentNode, | ||
selectedModules: ReadonlyArray<string>, | ||
options: ModuleSelectionOptions = {}, | ||
): ValidationResult { | ||
const projectToCheck = new Project({ | ||
sources: [new ProjectSource('to-check.graphql', print(docToCheck))], | ||
}); | ||
|
||
const projectWithModules = new Project({ | ||
sources: [ | ||
new ProjectSource('baseline.graphql', print(baselineDoc)), | ||
new ProjectSource( | ||
'modules.json', | ||
JSON.stringify({ modules: ['module1', 'module2', 'module3', 'extra1', 'extra2'] }), | ||
), | ||
], | ||
modelOptions: { withModuleDefinitions: true }, | ||
}); | ||
const baselineProject = projectWithModules.withModuleSelection(selectedModules); | ||
|
||
return projectToCheck.checkCompatibility(baselineProject); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.