Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rotten-scissors-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'hive': patch
'@graphql-hive/cli': patch
---

Restrict new service names to 64 characters, alphanumberic, \_, -, and /
237 changes: 237 additions & 0 deletions integration-tests/tests/cli/__snapshots__/schema.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,85 @@ stdout--------------------------------------------:
ℹ Available at http://__URL__
`;

exports[`FEDERATION > check validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
1
stderr--------------------------------------------:
__NONE__
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`FEDERATION > check validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
1
stderr--------------------------------------------:
__NONE__
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`FEDERATION > check validates the service name > success 1`] = `
:::::::::::::::: CLI SUCCESS OUTPUT :::::::::::::::::

stdout--------------------------------------------:
✔ Schema registry is empty, nothing to compare your schema with.
View full report:
http://__URL__
`;

exports[`FEDERATION > publish validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
› a complete list of error codes and recommended fixes.
› To disable this message set HIVE_NO_ERROR_TIP=1
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`FEDERATION > publish validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
› a complete list of error codes and recommended fixes.
› To disable this message set HIVE_NO_ERROR_TIP=1
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`FEDERATION > publish validates the service name > success 1`] = `
:::::::::::::::: CLI SUCCESS OUTPUT :::::::::::::::::

stdout--------------------------------------------:
✔ Published initial schema.
ℹ Available at http://__URL__
`;

exports[`FEDERATION > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
Expand Down Expand Up @@ -256,6 +335,85 @@ stdout--------------------------------------------:
ℹ Available at http://__URL__
`;

exports[`SINGLE > check validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
1
stderr--------------------------------------------:
__NONE__
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), underscore (_), or forward slash (/).


`;

exports[`SINGLE > check validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
1
stderr--------------------------------------------:
__NONE__
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), underscore (_), or forward slash (/).


`;

exports[`SINGLE > check validates the service name > success 1`] = `
:::::::::::::::: CLI SUCCESS OUTPUT :::::::::::::::::

stdout--------------------------------------------:
✔ Schema registry is empty, nothing to compare your schema with.
View full report:
http://__URL__
`;

exports[`SINGLE > publish validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
› a complete list of error codes and recommended fixes.
› To disable this message set HIVE_NO_ERROR_TIP=1
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), underscore (_), or forward slash (/).


`;

exports[`SINGLE > publish validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
› a complete list of error codes and recommended fixes.
› To disable this message set HIVE_NO_ERROR_TIP=1
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), underscore (_), or forward slash (/).


`;

exports[`SINGLE > publish validates the service name > success 1`] = `
:::::::::::::::: CLI SUCCESS OUTPUT :::::::::::::::::

stdout--------------------------------------------:
✔ Published initial schema.
ℹ Available at http://__URL__
`;

exports[`SINGLE > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
Expand Down Expand Up @@ -442,6 +600,85 @@ stdout--------------------------------------------:
ℹ Available at http://__URL__
`;

exports[`STITCHING > check validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
1
stderr--------------------------------------------:
__NONE__
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`STITCHING > check validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
1
stderr--------------------------------------------:
__NONE__
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`STITCHING > check validates the service name > success 1`] = `
:::::::::::::::: CLI SUCCESS OUTPUT :::::::::::::::::

stdout--------------------------------------------:
✔ Schema registry is empty, nothing to compare your schema with.
View full report:
http://__URL__
`;

exports[`STITCHING > publish validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
› a complete list of error codes and recommended fixes.
› To disable this message set HIVE_NO_ERROR_TIP=1
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`STITCHING > publish validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
› a complete list of error codes and recommended fixes.
› To disable this message set HIVE_NO_ERROR_TIP=1
stdout--------------------------------------------:
✖ Detected 1 error

- Invalid service name. Service name must be 64 characters or less, must start with a letter, and can only contain alphanumeric characters, dash (-), or underscore (_).


`;

exports[`STITCHING > publish validates the service name > success 1`] = `
:::::::::::::::: CLI SUCCESS OUTPUT :::::::::::::::::

stdout--------------------------------------------:
✔ Published initial schema.
ℹ Available at http://__URL__
`;

exports[`STITCHING > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
Expand Down
107 changes: 107 additions & 0 deletions integration-tests/tests/cli/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,113 @@ describe.each([ProjectType.Stitching, ProjectType.Federation, ProjectType.Single
},
);

test
.skipIf(projectType === ProjectType.Single)
.concurrent('publish validates the service name', async ({ expect }) => {
const { createOrg } = await initSeed().createOwner();
const { inviteAndJoinMember, createProject } = await createOrg();
await inviteAndJoinMember();
const { createTargetAccessToken } = await createProject(projectType);
const { secret } = await createTargetAccessToken({});

await expect(
schemaPublish([
'--registry.accessToken',
secret,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'900',
...serviceUrlArgs,
'fixtures/init-schema.graphql',
]),
).rejects.toMatchSnapshot('onlyNumbers');

await expect(
schemaPublish([
'--registry.accessToken',
secret,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'asdf$#%^#@!#',
...serviceUrlArgs,
'fixtures/init-schema.graphql',
]),
).rejects.toMatchSnapshot('specialCharacters');

await expect(
schemaPublish([
'--registry.accessToken',
secret,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'valid-name0',
...serviceUrlArgs,
'fixtures/init-schema.graphql',
]),
).resolves.toMatchSnapshot('success');
});

test
.skipIf(projectType === ProjectType.Single)
.concurrent('check validates the service name', async ({ expect }) => {
const { createOrg } = await initSeed().createOwner();
const { inviteAndJoinMember, createProject } = await createOrg();
await inviteAndJoinMember();
const { createTargetAccessToken } = await createProject(projectType);
const { secret } = await createTargetAccessToken({});

await expect(
schemaCheck([
'--registry.accessToken',
secret,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'900',
'fixtures/init-schema.graphql',
]),
).rejects.toMatchSnapshot('onlyNumbers');

await expect(
schemaCheck([
'--registry.accessToken',
secret,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'asdf$#%^#@!#',
'fixtures/init-schema.graphql',
]),
).rejects.toMatchSnapshot('specialCharacters');

await expect(
schemaCheck([
'--registry.accessToken',
secret,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'valid-name0',
'fixtures/init-schema.graphql',
]),
).resolves.toMatchSnapshot('success');
});

test.concurrent(
'publishing invalid schema SDL provides meaningful feedback for the user.',
async ({ expect }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function ensureSingleSchema(schema: Schema | Schema[]): SingleSchema {
throw new Error('Expected a single schema');
}

export function ensureCompositeSchemas(schemas: readonly Schema[]): CompositeSchema[] | never {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed this never was because the function threw an array, but it only filters. So I'm not sure why this never is here... removed.

export function ensureCompositeSchemas(schemas: readonly Schema[]): CompositeSchema[] {
return schemas.filter(isCompositeSchema);
}

Expand Down
Loading
Loading