Allow new interface style for GraphQL. (#4012)
* Allow new interface style for GraphQL. This is a breaking change since it will upgrade the old style to the new one. Closes #3600. * Allow old interface style. When in present of mixed style, it updates to the new one.master
parent
1b09fde361
commit
9da8752585
|
@ -33,7 +33,7 @@
|
|||
"flow-parser": "0.64.0",
|
||||
"get-stream": "3.0.0",
|
||||
"globby": "6.1.0",
|
||||
"graphql": "0.12.3",
|
||||
"graphql": "0.13.2",
|
||||
"gray-matter": "3.1.1",
|
||||
"html-tag-names": "1.1.1",
|
||||
"ignore": "3.3.7",
|
||||
|
|
|
@ -34,11 +34,19 @@ function removeTokens(node) {
|
|||
return node;
|
||||
}
|
||||
|
||||
function fallbackParser(parse, source) {
|
||||
try {
|
||||
return parse(source, { allowLegacySDLImplementsInterfaces: false });
|
||||
} catch (_) {
|
||||
return parse(source, { allowLegacySDLImplementsInterfaces: true });
|
||||
}
|
||||
}
|
||||
|
||||
function parse(text /*, parsers, opts*/) {
|
||||
// Inline the require to avoid loading all the JS if we don't use it
|
||||
const parser = require("graphql/language");
|
||||
try {
|
||||
const ast = parser.parse(text);
|
||||
const ast = fallbackParser(parser.parse, text);
|
||||
ast.comments = parseComments(ast);
|
||||
removeTokens(ast);
|
||||
return ast;
|
||||
|
|
|
@ -250,7 +250,18 @@ function genericPrint(path, options, print) {
|
|||
"type ",
|
||||
path.call(print, "name"),
|
||||
n.interfaces.length > 0
|
||||
? concat([" implements ", join(", ", path.map(print, "interfaces"))])
|
||||
? concat([
|
||||
" implements ",
|
||||
join(
|
||||
determineInterfaceSeparator(
|
||||
options.originalText.substr(
|
||||
options.locStart(n),
|
||||
options.locEnd(n)
|
||||
)
|
||||
),
|
||||
path.map(print, "interfaces")
|
||||
)
|
||||
])
|
||||
: "",
|
||||
printDirectives(path, print, n),
|
||||
n.fields.length > 0
|
||||
|
@ -620,6 +631,18 @@ function printComment(commentPath) {
|
|||
}
|
||||
}
|
||||
|
||||
function determineInterfaceSeparator(originalSource) {
|
||||
const start = originalSource.indexOf("implements");
|
||||
if (start === -1) {
|
||||
throw new Error("Must implement interfaces: " + originalSource);
|
||||
}
|
||||
let end = originalSource.indexOf("{");
|
||||
if (end === -1) {
|
||||
end = originalSource.length;
|
||||
}
|
||||
return originalSource.substr(start, end).includes("&") ? " & " : ", ";
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
print: genericPrint,
|
||||
hasPrettierIgnore: privateUtil.hasIgnoreComment,
|
||||
|
|
|
@ -12,3 +12,147 @@ interface Actor {
|
|||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`object_type_def.graphql 1`] = `
|
||||
type Artist implements Node & Entity {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
type Artist implements Node & Entity {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`object_type_def_mixed_syntax.graphql 1`] = `
|
||||
type MixedArtist implements Node, Entity & Releasable {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
type MixedArtist implements Node & Entity & Releasable {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`object_type_def_old_syntax.graphql 1`] = `
|
||||
type OldArtist implements Node, Entity {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
type OldArtist implements Node, Entity {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
}
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
type Artist implements Node & Entity {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
type MixedArtist implements Node, Entity & Releasable {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
type OldArtist implements Node, Entity {
|
||||
# The ID of an object
|
||||
id: ID!
|
||||
|
||||
# The MBID of the entity.
|
||||
mbid: MBID!
|
||||
|
||||
# A list of recordings linked to this entity.
|
||||
recordings(after: String, first: Int): RecordingConnection
|
||||
|
||||
# A list of releases linked to this entity.
|
||||
releases(
|
||||
# Filter by one or more release group types.
|
||||
type: [ReleaseGroupType]
|
||||
|
||||
# Filter by one or more release statuses.
|
||||
status: [ReleaseStatus]
|
||||
after: String
|
||||
first: Int
|
||||
): ReleaseConnection
|
||||
|
||||
}
|
14
yarn.lock
14
yarn.lock
|
@ -2149,11 +2149,11 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4:
|
|||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
|
||||
|
||||
graphql@0.12.3:
|
||||
version "0.12.3"
|
||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.12.3.tgz#11668458bbe28261c0dcb6e265f515ba79f6ce07"
|
||||
graphql@0.13.2:
|
||||
version "0.13.2"
|
||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270"
|
||||
dependencies:
|
||||
iterall "1.1.3"
|
||||
iterall "^1.2.1"
|
||||
|
||||
gray-matter@3.1.1:
|
||||
version "3.1.1"
|
||||
|
@ -2676,9 +2676,9 @@ istanbul-reports@^1.1.1:
|
|||
dependencies:
|
||||
handlebars "^4.0.3"
|
||||
|
||||
iterall@1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.3.tgz#1cbbff96204056dde6656e2ed2e2226d0e6d72c9"
|
||||
iterall@^1.2.1:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
|
||||
|
||||
jest-changed-files@^21.2.0:
|
||||
version "21.2.0"
|
||||
|
|
Loading…
Reference in New Issue