Update functions vars -> variables
This commit is contained in:
parent
734561c6b6
commit
f2af301f16
3 changed files with 118 additions and 22 deletions
|
@ -115,6 +115,13 @@ trait GraphQLBase
|
|||
public static string $GET_RUNTIMES = 'list_runtimes';
|
||||
public static string $UPDATE_FUNCTION = 'update_function';
|
||||
public static string $DELETE_FUNCTION = 'delete_function';
|
||||
// Variables
|
||||
public static string $CREATE_VARIABLE = 'create_variable';
|
||||
public static string $GET_VARIABLES = 'list_variables';
|
||||
public static string $GET_VARIABLE = 'get_variable';
|
||||
public static string $UPDATE_VARIABLE = 'update_variable';
|
||||
public static string $DELETE_VARIABLE = 'delete_variable';
|
||||
|
||||
//Deployments
|
||||
public static string $CREATE_DEPLOYMENT = 'create_deployment';
|
||||
public static string $GET_DEPLOYMENTS = 'list_deployments';
|
||||
|
@ -1126,8 +1133,8 @@ trait GraphQLBase
|
|||
}
|
||||
}';
|
||||
case self::$CREATE_FUNCTION:
|
||||
return 'mutation createFunction($functionId: String!, $name: String!, $execute: [String!]!, $runtime: String! $vars: Json, $events: [String], $schedule: String, $timeout: Int) {
|
||||
functionsCreate(functionId: $functionId, name: $name, execute: $execute, runtime: $runtime, vars: $vars, events: $events, schedule: $schedule, timeout: $timeout) {
|
||||
return 'mutation createFunction($functionId: String!, $name: String!, $execute: [String!]!, $runtime: String! $events: [String], $schedule: String, $timeout: Int) {
|
||||
functionsCreate(functionId: $functionId, name: $name, execute: $execute, runtime: $runtime, events: $events, schedule: $schedule, timeout: $timeout) {
|
||||
_id
|
||||
name
|
||||
runtime
|
||||
|
@ -1135,8 +1142,8 @@ trait GraphQLBase
|
|||
}
|
||||
}';
|
||||
case self::$UPDATE_FUNCTION:
|
||||
return 'mutation updateFunction($functionId: String!, $name: String!, $execute: [String!]!, $vars: Json, $events: [String], $schedule: String, $timeout: Int) {
|
||||
functionsUpdate(functionId: $functionId, name: $name, execute: $execute, vars: $vars, events: $events, schedule: $schedule, timeout: $timeout) {
|
||||
return 'mutation updateFunction($functionId: String!, $name: String!, $execute: [String!]!, $events: [String], $schedule: String, $timeout: Int) {
|
||||
functionsUpdate(functionId: $functionId, name: $name, execute: $execute, events: $events, schedule: $schedule, timeout: $timeout) {
|
||||
_id
|
||||
name
|
||||
runtime
|
||||
|
@ -1156,6 +1163,45 @@ trait GraphQLBase
|
|||
return 'mutation deleteFunction($functionId: String!) {
|
||||
functionsDelete(functionId: $functionId)
|
||||
}';
|
||||
case self::$CREATE_VARIABLE:
|
||||
return 'mutation createVariable($functionId: String!, $key: String!, $value: String!) {
|
||||
functionsCreateVariable(functionId: $functionId, key: $key, value: $value) {
|
||||
_id
|
||||
key
|
||||
value
|
||||
}
|
||||
}';
|
||||
case self::$GET_VARIABLES:
|
||||
return 'query listVariables($functionId: String!) {
|
||||
functionsListVariables(functionId: $functionId) {
|
||||
total
|
||||
variables {
|
||||
_id
|
||||
key
|
||||
value
|
||||
}
|
||||
}
|
||||
}';
|
||||
case self::$GET_VARIABLE:
|
||||
return 'query getVariable($functionId: String!, $variableId: String!) {
|
||||
functionsGetVariable(functionId: $functionId, variableId: $variableId) {
|
||||
_id
|
||||
key
|
||||
value
|
||||
}
|
||||
}';
|
||||
case self::$UPDATE_VARIABLE:
|
||||
return 'mutation updateVariable($functionId: String!, $variableId: String!, $key: String!, $value: String) {
|
||||
functionsUpdateVariable(functionId: $functionId, variableId: $variableId, key: $key, value: $value) {
|
||||
_id
|
||||
key
|
||||
value
|
||||
}
|
||||
}';
|
||||
case self::$DELETE_VARIABLE:
|
||||
return 'mutation deleteVariable($functionId: String!, $variableId: String!) {
|
||||
functionsDeleteVariable(functionId: $functionId, variableId: $variableId)
|
||||
}';
|
||||
case self::$CREATE_DEPLOYMENT:
|
||||
return 'mutation createDeployment($functionId: String!, $entrypoint: String!, $code: InputFile!, $activate: Boolean!) {
|
||||
functionsCreateDeployment(functionId: $functionId, entrypoint: $entrypoint, code: $code, activate: $activate) {
|
||||
|
|
|
@ -25,12 +25,8 @@ class GraphQLFunctionsClientTest extends Scope
|
|||
'variables' => [
|
||||
'functionId' => ID::unique(),
|
||||
'name' => 'Test Function',
|
||||
'runtime' => 'ruby-3.0',
|
||||
'vars' => [
|
||||
'name' => 'John Doe',
|
||||
'age' => 42,
|
||||
]
|
||||
'execute' => [Role::any()],
|
||||
'runtime' => 'php-8.0',
|
||||
'execute' => [Role::any()->toString()],
|
||||
]
|
||||
];
|
||||
|
||||
|
@ -40,10 +36,40 @@ class GraphQLFunctionsClientTest extends Scope
|
|||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], $gqlPayload);
|
||||
|
||||
|
||||
$this->assertIsArray($function['body']['data']);
|
||||
$this->assertArrayNotHasKey('errors', $function['body']);
|
||||
|
||||
return $function['body']['data']['functionsCreate'];
|
||||
$function = $function['body']['data']['functionsCreate'];
|
||||
$functionId = $function['_id'];
|
||||
|
||||
$query = '
|
||||
mutation createVariables($functionId: String!) {
|
||||
var1: functionsCreateVariable(functionId: $functionId, key: "name", value: "John Doe") {
|
||||
_id
|
||||
}
|
||||
var2: functionsCreateVariable(functionId: $functionId, key: "age", value: "42") {
|
||||
_id
|
||||
}
|
||||
}
|
||||
';
|
||||
$gqlPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'functionId' => $functionId,
|
||||
]
|
||||
];
|
||||
|
||||
$variables = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], $gqlPayload);
|
||||
|
||||
$this->assertIsArray($variables['body']['data']);
|
||||
$this->assertArrayNotHasKey('errors', $variables['body']);
|
||||
|
||||
return $function;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,13 +82,13 @@ class GraphQLFunctionsClientTest extends Scope
|
|||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$query = $this->getQuery(self::$CREATE_DEPLOYMENT);
|
||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/ruby/code.tar.gz";
|
||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/php/code.tar.gz";
|
||||
$gqlPayload = [
|
||||
'operations' => \json_encode([
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'functionId' => $function['_id'],
|
||||
'entrypoint' => 'main.rb',
|
||||
'entrypoint' => 'index.php',
|
||||
'activate' => true,
|
||||
'code' => null,
|
||||
]
|
||||
|
|
|
@ -25,12 +25,8 @@ class GraphQLFunctionsServerTest extends Scope
|
|||
'variables' => [
|
||||
'functionId' => ID::unique(),
|
||||
'name' => 'Test Function',
|
||||
'runtime' => 'ruby-3.0',
|
||||
'vars' => [
|
||||
'name' => 'John Doe',
|
||||
'age' => 42,
|
||||
]
|
||||
'execute' => [Role::any()],
|
||||
'runtime' => 'php-8.0',
|
||||
'execute' => [Role::any()->toString()],
|
||||
]
|
||||
];
|
||||
|
||||
|
@ -41,7 +37,35 @@ class GraphQLFunctionsServerTest extends Scope
|
|||
|
||||
$this->assertIsArray($function['body']['data']);
|
||||
$this->assertArrayNotHasKey('errors', $function['body']);
|
||||
|
||||
$function = $function['body']['data']['functionsCreate'];
|
||||
$functionId = $function['_id'];
|
||||
|
||||
$query = '
|
||||
mutation createVariables($functionId: String!) {
|
||||
var1: functionsCreateVariable(functionId: $functionId, key: "name", value: "John Doe") {
|
||||
_id
|
||||
}
|
||||
var2: functionsCreateVariable(functionId: $functionId, key: "age", value: "42") {
|
||||
_id
|
||||
}
|
||||
}
|
||||
';
|
||||
$gqlPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'functionId' => $functionId,
|
||||
]
|
||||
];
|
||||
|
||||
$variables = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], $gqlPayload);
|
||||
|
||||
$this->assertIsArray($variables['body']['data']);
|
||||
$this->assertArrayNotHasKey('errors', $variables['body']);
|
||||
|
||||
return $function;
|
||||
}
|
||||
|
@ -56,13 +80,13 @@ class GraphQLFunctionsServerTest extends Scope
|
|||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$query = $this->getQuery(self::$CREATE_DEPLOYMENT);
|
||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/ruby/code.tar.gz";
|
||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/php/code.tar.gz";
|
||||
$gqlPayload = [
|
||||
'operations' => \json_encode([
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'functionId' => $function['_id'],
|
||||
'entrypoint' => 'main.rb',
|
||||
'entrypoint' => 'index.php',
|
||||
'activate' => true,
|
||||
'code' => null,
|
||||
]
|
||||
|
@ -357,7 +381,7 @@ class GraphQLFunctionsServerTest extends Scope
|
|||
'variables' => [
|
||||
'functionId' => $function['_id'],
|
||||
'name' => 'Test Function Updated',
|
||||
'execute' => [Role::any()],
|
||||
'execute' => [Role::any()->toString()],
|
||||
'vars' => [
|
||||
'name' => 'John Doe',
|
||||
'age' => 42,
|
||||
|
|
Loading…
Reference in a new issue