Hi Folks, I want to add roles to the users using graphQL API given below. const ADD_USER_ROLE_MUTATION = gql`
mutation addUsersToRole($roleKey: RoleKeyInput!, $users: [UserIdInput!]!) {
...
yogeshdixitChange the package name to "@customer/catfact-endpoint". If it still doesn’t work then request the Khoros support team to restart the community.
yogeshdixitKhoros Support recommended not using any external libraries in endpoints. I noticed that you have used axios. Instead, please use fetch from the context
Could you please help me out with the query syntax in endpoint mutation query. Below is my Endpoint code and User graphql query. I want to send the variable getting from request.body to assign the role to a particular user
Endpoint Code
// import { gql } from '@apollo/client';
import type { EndpointHandlerContext } from 'aurora/externalServerContext';
import type { RouteParameters } from 'express-serve-static-core';
import graphqlQuery from './queries/Users.query.graphql';
async function handler(context: EndpointHandlerContext<RouteParameters<string>>) {
const {
client: { graphqlAdmin },
server: { request, response },
utils: { log }
} = context;
try {
// Parse the request body
const { body } = request;
// Log the received data
log.info('Handling request to assign a role to a user', body); // {"roleKey":{"roleName":"Test AMA Adventurer"},"users":[{"id":"user:203"}]}
// Execute the mutation
const queryResponse = await graphqlAdmin.mutate({
mutation: graphqlQuery,
How to pass variable Here {"roleKey":{"roleName":"Test AMA Adventurer"},"users":[{"id":"user:203"}]}
});
log.info(queryResponse);
response.json(request.body);
} catch (error) {
log.error('Error while handling the request', error);
}
}
export default handler;
Query import graphqlQuery from './queries/Users.query.graphql'
mutation addUsersToRole($roleKey: RoleKeyInput!, $users: [UserIdInput!]!) {
addUsersToRole(roleKey: $roleKey, users: $users) {
result {
id
name
description
}
errors {
... on GreaterThanMaxValueError {
key
fields
max
message
}
}
}
}
As shown in the screenshot marked with arrow
Request.body = {"roleKey":{"roleName":"Test AMA Adventurer"},"users":[{"id":"user:203"}]}