9 months ago
I am try to change service limits using the API, but when I call the endpoint no error is returned and the limits don't change.
All others endpoints I'm using are working properly.
This is the code I am using. (Please ignore missing variables). Do I making something wrong or missing some?
import { gql, request, type RequestDocument } from "graphql-request";
const query = async (
query: RequestDocument,
variables: Record<string, any>,
) => {
const token = env.get("RAILWAY_TOKEN");
const headers = { Authorization: `Bearer ${token}` };
const data = await request(BASEURL, query, variables, headers);
return data;
};
const UPDATE_LIMITS = gql`
mutation serviceInstanceLimitsUpdate(
$input: ServiceInstanceLimitsUpdateInput!
) {
serviceInstanceLimitsUpdate(input: $input)
}
`;
await query(UPDATE_LIMITS, {
input: {
serviceId,
environmentId: ENVIRONMENT_ID,
vCPUs: 1,
memoryGB: 1,
},
});3 Replies
9 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
9 months ago
Hmmmm...
I would use our EnvironmentPatch system not that API as this is how we do this on the front-end.
```
import { gql, request } from "graphql-request";
// Stage changes first
const STAGE_CHANGES = gql`
mutation environmentPatchStage($input: EnvironmentPatchStageInput!) {
environmentPatchStage(input: $input)
}
`;
// Then apply them
const APPLY_CHANGES = gql`
mutation environmentPatchApply(
$environmentId: String!
$patch: EnvironmentConfig!
$commitMessage: String
) {
environmentPatchApply(
environmentId: $environmentId
patch: $patch
commitMessage: $commitMessage
)
}
`;
// Stage the changes
await query(STAGE_CHANGES, {
input: {
environmentId: ENVIRONMENT_ID,
patch: {
services: {
[serviceId]: {
deploy: {
limitOverride: {
containers: {
cpu: 1,
memoryBytes: 1073741824 // 1GB in bytes
}
}
}
}
}
}
}
});
// Apply the staged changes
await query(APPLY_CHANGES, {
environmentId: ENVIRONMENT_ID,
patch: {
services: {
[serviceId]: {
deploy: {
limitOverride: {
containers: {
cpu: 1,
memoryBytes: 1073741824 // 1GB in bytes
}
}
}
}
}
},
commitMessage: "Update service resource limits"
});
```
Like so- let me know if this helps.
Status changed to Awaiting User Response Railway • 9 months ago
9 months ago
Hi, Angelo.
I made some changes to what you sent, and this worked for me:
const APPLY_CHANGES = gql`
mutation environmentPatchCommit(
$environmentId: String!
$patch: EnvironmentConfig!
$commitMessage: String
) {
environmentPatchCommit(
environmentId: $environmentId
patch: $patch
commitMessage: $commitMessage
)
}
`;Now, my problem is that I can’t find the definition of EnvironmentConfig. When I open it in GraphQL Playground, I can see the type, but when I click to view its contents, it’s empty.
In any case, thank you. Your answer was very helpful.
Attachments
Status changed to Awaiting Railway Response Railway • 9 months ago
Status changed to Solved brunoziie • 9 months ago