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.
I have a function with an axios call in a component. When hitting the endpoint, it returns a 400 Bad Request. Could you please help me understand what could be the issue?
Also, Do you have any documentation reference that includes a mutation query for the endpoint? I am trying to update the user using graphqlAdmin, but sometimes it returns a 404 Not Found or 400 Bad Request error.
Below is my mutation code in index.ts file.
Payload of below query:
import { gql } from '@apollo/client';
import type { EndpointHandlerContext } from 'aurora/externalServerContext';
import type { RouteParameters } from 'express-serve-static-core';
interface QueryResponse {
data: {
addUsersToRole: {
result?: {
id: string;
name: string;
};
errors?: {
message: string;
};
};
};
}
const ADD_USER_ROLE_MUTATION = gql`
mutation addUsersToRole($roleKey: RoleKeyInput!, $users: [UserIdInput!]!) {
addUsersToRole(roleKey: $roleKey, users: $users) {
result {
id
name
description
}
errors {
... on GreaterThanMaxValueError {
key
fields
max
message
}
}
}
}
`;
async function handler(context: EndpointHandlerContext<RouteParameters<string>>) {
const {
client: { graphql },
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:12"}]}
// Send the parsed body data back as JSON
// Execute the mutation
const queryResponse: QueryResponse = await graphql.query({
query: ADD_USER_ROLE_MUTATION,
variables: { body }
});
response.json(queryResponse);
} catch (error) {
log.error('Error while handling the request', error);
}
}
export default handler;