Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK should support GraphQL #5

Closed
tcaruth opened this issue Feb 13, 2023 · 7 comments
Closed

SDK should support GraphQL #5

tcaruth opened this issue Feb 13, 2023 · 7 comments

Comments

@tcaruth
Copy link
Contributor

tcaruth commented Feb 13, 2023

I'm imagining a new method on the delivery, preview, and management clients that submit graphQL queries and returns the result as an object
https://docs.oracle.com/en/cloud/paas/content-cloud/solutions/graphql-support-oracle-content-management.html

/content/preview/api/v1.1/graphql
/content/published/api/v1.1/graphql

await contentClient.graphQL(query, variables)

// returns
{ 
  data: {
    getItem //etc
  }
}
@kmacdonaO
Copy link
Contributor

Hi Travis, we actually have added a method to the SDK to do this and are preparing to publish it to GitHub. Here are two examples of usage:

`Examples
// get the id,name,type of all the items in the publishing channel
contentClient.graphql({
'query': '{ getItems(channelToken: "2834f431f8524ffa89dfb7fe77993284")
{ items { id name type } } }'
}).then(function (response) {
console.log(response);
});

// get the item slug with the corresponding id in a channel
contentClient.graphql({
'query': '{ getItem(id:"CORE51A353B7C6AA4EB29C74781FB418C93B",
channelToken:"546c6bdfe022455db92741407cccded3")
{ slug } }'
}).then(function (response) {
console.log(response);
});
`
do you think this will satisfy the requirements that you have?

@tcaruth
Copy link
Contributor Author

tcaruth commented Feb 14, 2023

Does your method support variables?

@kmacdonaO
Copy link
Contributor

kmacdonaO commented Feb 16, 2023

Yes, it does support variables - I spent some time today adding tests to validate variable usage. Usage in my test looks like:

const response = await sut.graphql({
      query: 'query ($itemId: ID, $channelToken: String) {getItem(id: $itemId, channelToken: $channelToken) {id}}',
      variables: {
        itemId: process.env.VALID_DIGITAL_ASSET_ID_BASIC,
        channelToken: process.env.CHANNEL_TOKEN_BASIC,
      },
    });

I have a few other tests to fix up and then I'll publish this to GitHub soon

@tcaruth
Copy link
Contributor Author

tcaruth commented Feb 17, 2023

Looks good to me. Once it's on GitHub, how long do you think OCM adoption will take?

@kmacdonaO
Copy link
Contributor

The package has been published to npmjs now - are you consuming this SDK directly via your OCM service (e.g. for content layouts)?

@tcaruth
Copy link
Contributor Author

tcaruth commented Feb 18, 2023 via email

@kmacdonaO
Copy link
Contributor

We're working to unify the code that is published on the server with the github/npmjs codebase. The server code is much older though I think it does have a graphql method already which you can probably use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants