Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@graphcms/management
Advanced tools
Programmatically manage GraphCMS project schema via migrations.
Join us on Slack • Login to GraphCMS • @GraphCMS
const { newMigration, FieldType } = require("@graphcms/management");
const migration = newMigration({ endpoint: "...", authToken: "..." });
const author = migration.createModel({
apiId: "Author",
apiIdPlural: "Authors",
displayName: "Author",
});
author.addSimpleField({
apiId: "firstName",
displayName: "First Name",
type: FieldType.String,
});
author.addSimpleField({
apiId: "lastName",
displayName: "Last Name",
type: FieldType.String,
});
migration.run();
npm install @graphcms/management --save-dev
Changes to your schema starts with a migration.
A migration is scoped to an environment. To create a migration, the following parameters are required.
Authentication Token authToken
.
Can be retrieved from Settings > API Access
on https://app.graphcms.com
Environment URL endpoint
.
Can be retrieved from Settings > Environments
on https://app.graphcms.com
Migration Name name
[optional].
Every migration has a unique name. If unspecified, a name would be generated and will be part of the response of a successful migration.
Subsequent migrations with same name will fail.
const { newMigration } = require("@graphcms/management");
const migration = newMigration({
authToken,
endpoint,
name, // optional
});
The run
method runs the migration.
By default, migrations run in the background. Passing an optional boolean argument configures the migration to run in the foreground.
const foreground = true;
const result = migration.run(foreground);
if (result.errors) {
console.log(result.errors);
} else {
console.log(result.name);
}
A migration can be dry run to preview what changes would be applied.
const changes = migration.dryRun();
console.log(changes);
To update properties, specify the properties to be updated. All ommitted properties remain unmodified.
As a special case, apiId
is a requirement because all entities are uniquely indentified by apiId
.
To update the apiId
, specify newApiId
.
GraphCMS boasts a flexible localization API that you can use to publish content for all or specific locales in your project.
To create a locale
migration.createLocale({
apiId,
displayName,
description,
});
To update a locale
migration.updateLocale({
apiId,
... // properties to update
});
To delete a locale
migration.deleteLocale(apiId);
You can create your own content stages, and query content from these stages, as well as publish to.
To create a stage
migration.createStage({
apiId,
displayName,
description,
isDefault,
allowQueries,
color,
});
To update a stage
migration.updateStage({
apiId,
... // properties to update
});
To delete a Stage
migration.deleteStage(apiId);
Enums values can only contain alphanumeric characters, and underscores.
Create an enumeration with values.
const colors = migration.createEnumeration({
apiId,
displayName,
description,
});
// add values
colors.addValue("Red");
colors.addValue("Green");
// or add multiple values at a time.
colors.addValue("Blue", "Yellow");
Updating an enumeration and it's values.
const colors = migration.updateEnumeration({
apiId,
... // properties to update.
});
colors.addValue("Black"); // add a new value
colors.updateValue("Red", "Dark Red"); // update existing value
colors.deleteValue("Blue"); // delete value
To delete an enumeration and it's values
migration.deleteEnumeration(apiId);
Your schema is defined by the models you create, and fields you add.
A model can be created by passing in the required parameters.
const modelName = migration.createModel({
apiId, // must start with upper case letter
apiIdPlural, // must start with upper case letter
displayName,
description,
});
To update a model
migration.updateModel({
apiId, // required
... // properties to update
});
To delete a model
migration.deleteModel(apiId);
Your schema is built up of GraphQL types. If you’re familiar working with GraphQL, you should feel right at home. GraphCMS supports all of the common GraphQL types you are used to, as well as some of its own.
To create a simple field.
const { FieldType } = require("@graphcms/management");
model.addSimpleField({
apiId: '...',
displayName: '...',
type: FieldType.String,
});
String fields have several form renderers, including single line, multiline, markdown, and slug. You can set the form renderer as follows:
const { FieldType, Renderer } = require("@graphcms/management");
model.addSimpleField({
apiId: '...',
displayName: '...',
type: FieldType.String,
formRenderer: Renderer.MultiLine
});
To create an enumerable field.
model.addEnumerableField({
apiId,
displayName,
enumerationApiId, // previously created enumeration.
});
To create a relational field.
const { RelationType } = require("@graphcms/management");
model.addRelationalField({
apiId,
displayName,
relationType: RelationType.OneToOne,
model, // the related model
// optional but can be specified to customize the details.
reverseField: {
apiId,
displayName,
},
});
To create an asset field.
model.addRelationalField({
apiId,
displayName,
model: "Asset", // this is compulsory to indicate Asset field.
// optional but can be specified to customize the details.
reverseField: {
apiId,
displayName,
},
});
To create a union field.
const { RelationType } = require("@graphcms/management");
model.addUnionField({
apiId,
displayName,
relationType: RelationType.OneToOne,
models, // list of related models
// optional but can be specified to customize the details.
reverseField: {
apiId,
displayName,
},
});
To update a field, firstly retrieve the model.
const model = migration.updateModel({...}) // to update the model
const model = migration.model(apiId) // to only retrieve the model
Updating simple field
model.updateSimpleField({
apiId,
... // properties to update
})
Updating enumerable field
model.updateEnumerableField({
apiId,
... // properties to update
})
Updating relational field
model.updateRelationalField({
apiId,
... // properties to update
})
Updating union field
model.updateUnionField({
apiId,
models, // list of related models
... // properties to update
})
To delete a field
model.deleteField(apiId);
Thanks goes to these wonderful people (emoji key):
To update the Management API schema this SDK depends on you must run npm run generate
.
PR titles must follow Conventional Commits to publish to NPM automatically.
FAQs
GraphCMS Management SDK
We found that @graphcms/management demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.