Skip to content

Commit

Permalink
Bug: old management sdk in management example (#268)
Browse files Browse the repository at this point in the history
* Working version with the new SDK

* Cleans up format with prettier
  • Loading branch information
brob authored Jul 17, 2023
1 parent 326c30b commit a1a3c61
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 112 deletions.
2 changes: 1 addition & 1 deletion using-management-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node src/index.js"
},
"dependencies": {
"@graphcms/management": "1.1.0"
"@hygraph/management-sdk": "^1.2.1"
},
"devDependencies": {
"dotenv": "10.0.0"
Expand Down
60 changes: 32 additions & 28 deletions using-management-sdk/src/index.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
require('dotenv').config();

const {
newMigration,
FieldType,
RelationType,
Renderer,
} = require('@graphcms/management');
Client,
SimpleFieldType,
RelationalFieldType,
} = require('@hygraph/management-sdk');

// Create a new `migration` instance
const migration = newMigration({
const client = new Client({
authToken: process.env.HYGRAPH_MIGRATION_TOKEN,
endpoint: process.env.HYGRAPH_ENDPOINT,
});

// create model for blog
const blogModel = migration.createModel({
client.createModel({
apiId: 'Blog',
apiIdPlural: 'Blogs',
displayName: 'Blog',
});

// add blog fields
blogModel.addSimpleField({
client.createSimpleField({
apiId: 'title',
displayName: 'Title',
type: FieldType.String,
modelApiId: 'Blog',
type: SimpleFieldType.String,
});

blogModel.addSimpleField({
client.createSimpleField({
apiId: 'excerpt',
displayName: 'Excerpt',
type: FieldType.String,
formRenderer: Renderer.MultiLine,
modelApiId: 'Blog',
type: SimpleFieldType.String,
formRenderer: 'GCMS_MULTI_LINE',
});

blogModel.addSimpleField({
client.createSimpleField({
apiId: 'content',
displayName: 'Content',
type: FieldType.Richtext,
modelApiId: 'Blog',
type: SimpleFieldType.Richtext,
});

// create model for author
const authorModel = migration.createModel({
client.createModel({
apiId: 'Author',
apiIdPlural: 'Authors',
displayName: 'Author',
});

// add author fields
authorModel.addSimpleField({
client.createSimpleField({
apiId: 'name',
displayName: 'Name',
type: FieldType.String,
modelApiId: 'Author',
type: SimpleFieldType.String,
});

// add relation to blog for author posts

// create model for author
const authorRelation = migration.updateModel({
apiId: 'Author',
});

authorRelation.addRelationalField({
apiId: 'authorPosts',
displayName: 'Author Posts',
relationType: RelationType.OneToMany,
model: 'Blog',
client.createRelationalField({
parentApiId: 'Blog',
apiId: 'author',
displayName: 'Written By',
type: RelationalFieldType.Relation,
reverseField: {
modelApiId: 'Author',
apiId: 'posts',
displayName: 'Posts',
isList: true,
},
});

migration.run();
client.run();
208 changes: 125 additions & 83 deletions using-management-sdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,144 @@


"@graphcms/[email protected]":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@graphcms/management/-/management-1.1.0.tgz#7799d4faf010102dd0a142c60df230f9ead0cb43"
integrity sha512-jN+qu06BvvX2fK+tz8Po1ySV43ls4iLqQzNxVyoCyHZTwKEQPOVkvp4TRpusTOkuTxyOeI5r+s1GnKfUeQdPdQ==
"integrity" "sha512-jN+qu06BvvX2fK+tz8Po1ySV43ls4iLqQzNxVyoCyHZTwKEQPOVkvp4TRpusTOkuTxyOeI5r+s1GnKfUeQdPdQ=="
"resolved" "https://registry.npmjs.org/@graphcms/management/-/management-1.1.0.tgz"
"version" "1.1.0"
dependencies:
"@types/nanoid" "2.1.0"
graphql "15.5.0"
graphql-request "3.4.0"
nanoid "3.1.22"
"graphql" "15.5.0"
"graphql-request" "3.4.0"
"nanoid" "3.1.22"

"@hygraph/management-sdk@^1.2.1":
"integrity" "sha512-n9Vs29lZXWZdOB7NIy8eoNiQfPiVK5JQ/f0z6LJ434aC5JUHxa1fuzE+Rsq6ntTlTYTXaYMRqvsOHjFtRH9ovw=="
"resolved" "https://registry.npmjs.org/@hygraph/management-sdk/-/management-sdk-1.2.1.tgz"
"version" "1.2.1"
dependencies:
"graphql" "^16.5.0"
"graphql-request" "^4.3.0"

"@types/[email protected]":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@types/nanoid/-/nanoid-2.1.0.tgz#41edfda78986e9127d0dc14de982de766f994020"
integrity sha512-xdkn/oRTA0GSNPLIKZgHWqDTWZsVrieKomxJBOQUK9YDD+zfSgmwD5t4WJYra5S7XyhTw7tfvwznW+pFexaepQ==
"integrity" "sha512-xdkn/oRTA0GSNPLIKZgHWqDTWZsVrieKomxJBOQUK9YDD+zfSgmwD5t4WJYra5S7XyhTw7tfvwznW+pFexaepQ=="
"resolved" "https://registry.npmjs.org/@types/nanoid/-/nanoid-2.1.0.tgz"
"version" "2.1.0"
dependencies:
"@types/node" "*"

"@types/node@*":
version "15.12.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.12.4.tgz#e1cf817d70a1e118e81922c4ff6683ce9d422e26"
integrity sha512-zrNj1+yqYF4WskCMOHwN+w9iuD12+dGm0rQ35HLl9/Ouuq52cEtd0CH9qMgrdNmi5ejC1/V7vKEXYubB+65DkA==

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
"integrity" "sha512-zrNj1+yqYF4WskCMOHwN+w9iuD12+dGm0rQ35HLl9/Ouuq52cEtd0CH9qMgrdNmi5ejC1/V7vKEXYubB+65DkA=="
"resolved" "https://registry.npmjs.org/@types/node/-/node-15.12.4.tgz"
"version" "15.12.4"

"asynckit@^0.4.0":
"integrity" "sha1-x57Zf380y48robyXkLzDZkdLS3k= sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
"resolved" "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz"
"version" "0.4.0"

"combined-stream@^1.0.8":
"integrity" "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="
"resolved" "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
"version" "1.0.8"
dependencies:
delayed-stream "~1.0.0"
"delayed-stream" "~1.0.0"

cross-fetch@^3.0.6:
version "3.1.4"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.4.tgz#9723f3a3a247bf8b89039f3a380a9244e8fa2f39"
integrity sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==
"cross-fetch@^3.0.6", "cross-fetch@^3.1.5":
"integrity" "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg=="
"resolved" "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz"
"version" "3.1.8"
dependencies:
"node-fetch" "^2.6.12"

"delayed-stream@~1.0.0":
"integrity" "sha1-3zrhmayt+31ECqrgsp4icrJOxhk= sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
"resolved" "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz"
"version" "1.0.0"

"[email protected]":
"integrity" "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
"resolved" "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz"
"version" "10.0.0"

"extract-files@^9.0.0":
"integrity" "sha512-CvdFfHkC95B4bBBk36hcEmvdR2awOdhhVUYH6S/zrVj3477zven/fJMYg7121h4T1xHZC+tetUpubpAhxwI7hQ=="
"resolved" "https://registry.npmjs.org/extract-files/-/extract-files-9.0.0.tgz"
"version" "9.0.0"

"form-data@^3.0.0":
"integrity" "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg=="
"resolved" "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz"
"version" "3.0.1"
dependencies:
node-fetch "2.6.1"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

[email protected]:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

extract-files@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/extract-files/-/extract-files-9.0.0.tgz#8a7744f2437f81f5ed3250ed9f1550de902fe54a"
integrity sha512-CvdFfHkC95B4bBBk36hcEmvdR2awOdhhVUYH6S/zrVj3477zven/fJMYg7121h4T1xHZC+tetUpubpAhxwI7hQ==

form-data@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
"asynckit" "^0.4.0"
"combined-stream" "^1.0.8"
"mime-types" "^2.1.12"

"graphql-request@^4.3.0":
"integrity" "sha512-2v6hQViJvSsifK606AliqiNiijb1uwWp6Re7o0RTyH+uRTv/u7Uqm2g4Fjq/LgZIzARB38RZEvVBFOQOVdlBow=="
"resolved" "https://registry.npmjs.org/graphql-request/-/graphql-request-4.3.0.tgz"
"version" "4.3.0"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

[email protected]:
version "3.4.0"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-3.4.0.tgz#3a400cd5511eb3c064b1873afb059196bbea9c2b"
integrity sha512-acrTzidSlwAj8wBNO7Q/UQHS8T+z5qRGquCQRv9J1InwR01BBWV9ObnoE+JS5nCCEj8wSGS0yrDXVDoRiKZuOg==
"cross-fetch" "^3.1.5"
"extract-files" "^9.0.0"
"form-data" "^3.0.0"

"[email protected]":
"integrity" "sha512-acrTzidSlwAj8wBNO7Q/UQHS8T+z5qRGquCQRv9J1InwR01BBWV9ObnoE+JS5nCCEj8wSGS0yrDXVDoRiKZuOg=="
"resolved" "https://registry.npmjs.org/graphql-request/-/graphql-request-3.4.0.tgz"
"version" "3.4.0"
dependencies:
cross-fetch "^3.0.6"
extract-files "^9.0.0"
form-data "^3.0.0"

[email protected]:
version "15.5.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.5.0.tgz#39d19494dbe69d1ea719915b578bf920344a69d5"
integrity sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA==

[email protected]:
version "1.48.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.48.0.tgz#e35b31045dd7eada3aaad537ed88a33afbef2d1d"
integrity sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==

mime-types@^2.1.12:
version "2.1.31"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.31.tgz#a00d76b74317c61f9c2db2218b8e9f8e9c5c9e6b"
integrity sha512-XGZnNzm3QvgKxa8dpzyhFTHmpP3l5YNusmne07VUOXxou9CqUqYa/HBy124RqtVh/O2pECas/MOcsDgpilPOPg==
"cross-fetch" "^3.0.6"
"extract-files" "^9.0.0"
"form-data" "^3.0.0"

"graphql@^16.5.0", "graphql@14 - 16":
"integrity" "sha512-DRYR9tf+UGU0KOsMcKAlXeFfX89UiiIZ0dRU3mR0yJfu6OjZqUcp68NnFLnqQU5RexygFoDy1EW+ccOYcPfmHg=="
"resolved" "https://registry.npmjs.org/graphql/-/graphql-16.7.1.tgz"
"version" "16.7.1"

"[email protected] || 15.x", "[email protected]":
"integrity" "sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA=="
"resolved" "https://registry.npmjs.org/graphql/-/graphql-15.5.0.tgz"
"version" "15.5.0"

"[email protected]":
"integrity" "sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ=="
"resolved" "https://registry.npmjs.org/mime-db/-/mime-db-1.48.0.tgz"
"version" "1.48.0"

"mime-types@^2.1.12":
"integrity" "sha512-XGZnNzm3QvgKxa8dpzyhFTHmpP3l5YNusmne07VUOXxou9CqUqYa/HBy124RqtVh/O2pECas/MOcsDgpilPOPg=="
"resolved" "https://registry.npmjs.org/mime-types/-/mime-types-2.1.31.tgz"
"version" "2.1.31"
dependencies:
mime-db "1.48.0"
"mime-db" "1.48.0"

[email protected]:
version "3.1.22"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.22.tgz#b35f8fb7d151990a8aebd5aa5015c03cf726f844"
integrity sha512-/2ZUaJX2ANuLtTvqTlgqBQNJoQO398KyJgZloL0PZkC0dpysjncRUPsFe3DUPzz/y3h+u7C46np8RMuvF3jsSQ==
"[email protected]":
"integrity" "sha512-/2ZUaJX2ANuLtTvqTlgqBQNJoQO398KyJgZloL0PZkC0dpysjncRUPsFe3DUPzz/y3h+u7C46np8RMuvF3jsSQ=="
"resolved" "https://registry.npmjs.org/nanoid/-/nanoid-3.1.22.tgz"
"version" "3.1.22"

[email protected]:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
"node-fetch@^2.6.12":
"integrity" "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g=="
"resolved" "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz"
"version" "2.6.12"
dependencies:
"whatwg-url" "^5.0.0"

"tr46@~0.0.3":
"integrity" "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
"resolved" "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
"version" "0.0.3"

"webidl-conversions@^3.0.0":
"integrity" "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
"resolved" "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz"
"version" "3.0.1"

"whatwg-url@^5.0.0":
"integrity" "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="
"resolved" "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz"
"version" "5.0.0"
dependencies:
"tr46" "~0.0.3"
"webidl-conversions" "^3.0.0"

0 comments on commit a1a3c61

Please sign in to comment.