Use labels parameters to add extra methods to spec
This commit is contained in:
parent
c05c759eac
commit
8320fc0686
|
@ -22,12 +22,12 @@ App::get('/v1/graphql')
|
||||||
->label('sdk.namespace', 'graphql')
|
->label('sdk.namespace', 'graphql')
|
||||||
->label('sdk.method', 'query')
|
->label('sdk.method', 'query')
|
||||||
->label('sdk.description', '/docs/references/graphql/query.md')
|
->label('sdk.description', '/docs/references/graphql/query.md')
|
||||||
|
->label('sdk.parameters', ['query' => ['default' => '', 'validator' => new JSON(), 'description' => 'The query or queries to execute.', 'optional' => false]])
|
||||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
->label('sdk.response.model', Response::MODEL_ANY)
|
->label('sdk.response.model', Response::MODEL_ANY)
|
||||||
->label('abuse-limit', 60)
|
->label('abuse-limit', 60)
|
||||||
->label('abuse-time', 60)
|
->label('abuse-time', 60)
|
||||||
->param('query', '', new JSON(), 'The query or queries to execute.', fullBody: true)
|
|
||||||
->inject('request')
|
->inject('request')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('promiseAdapter')
|
->inject('promiseAdapter')
|
||||||
|
@ -42,12 +42,12 @@ App::post('/v1/graphql')
|
||||||
->label('sdk.namespace', 'graphql')
|
->label('sdk.namespace', 'graphql')
|
||||||
->label('sdk.method', 'mutate')
|
->label('sdk.method', 'mutate')
|
||||||
->label('sdk.description', '/docs/references/graphql/mutate.md')
|
->label('sdk.description', '/docs/references/graphql/mutate.md')
|
||||||
|
->label('sdk.parameters', ['query' => ['default' => '', 'validator' => new JSON(), 'description' => 'The query or queries to execute.', 'optional' => false]])
|
||||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
->label('sdk.response.model', Response::MODEL_ANY)
|
->label('sdk.response.model', Response::MODEL_ANY)
|
||||||
->label('abuse-limit', 60)
|
->label('abuse-limit', 60)
|
||||||
->label('abuse-time', 60)
|
->label('abuse-time', 60)
|
||||||
->param('query', '', new JSON(), 'The query or queries to execute.', fullBody: true)
|
|
||||||
->inject('request')
|
->inject('request')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('promiseAdapter')
|
->inject('promiseAdapter')
|
||||||
|
@ -60,16 +60,16 @@ App::post('/v1/graphql/upload')
|
||||||
->label('scope', 'graphql')
|
->label('scope', 'graphql')
|
||||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_JWT])
|
->label('sdk.auth', [APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_JWT])
|
||||||
->label('sdk.namespace', 'graphql')
|
->label('sdk.namespace', 'graphql')
|
||||||
->label('sdk.description', '/docs/references/graphql/upload.md')
|
|
||||||
->label('sdk.method', 'upload')
|
->label('sdk.method', 'upload')
|
||||||
|
->label('sdk.description', '/docs/references/graphql/upload.md')
|
||||||
->label('sdk.methodType', 'upload')
|
->label('sdk.methodType', 'upload')
|
||||||
|
->label('sdk.parameters', ['query' => ['default' => '', 'validator' => new JSON(), 'description' => 'The query or queries to execute.', 'optional' => false]])
|
||||||
->label('sdk.request.type', 'multipart/form-data')
|
->label('sdk.request.type', 'multipart/form-data')
|
||||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
->label('sdk.response.model', Response::MODEL_ANY)
|
->label('sdk.response.model', Response::MODEL_ANY)
|
||||||
->label('abuse-limit', 60)
|
->label('abuse-limit', 60)
|
||||||
->label('abuse-time', 60)
|
->label('abuse-time', 60)
|
||||||
->param('query', '', new JSON(), 'The query or queries to execute.', fullBody: true)
|
|
||||||
->inject('request')
|
->inject('request')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('promiseAdapter')
|
->inject('promiseAdapter')
|
||||||
|
@ -80,7 +80,6 @@ App::post('/v1/graphql/upload')
|
||||||
/**
|
/**
|
||||||
* Execute a GraphQL request
|
* Execute a GraphQL request
|
||||||
*
|
*
|
||||||
* @param array $query
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param CoroutinePromiseAdapter $promiseAdapter
|
* @param CoroutinePromiseAdapter $promiseAdapter
|
||||||
|
@ -89,13 +88,14 @@ App::post('/v1/graphql/upload')
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function executeRequest(
|
function executeRequest(
|
||||||
array $query,
|
|
||||||
Appwrite\Utopia\Request $request,
|
Appwrite\Utopia\Request $request,
|
||||||
Appwrite\Utopia\Response $response,
|
Appwrite\Utopia\Response $response,
|
||||||
CoroutinePromiseAdapter $promiseAdapter,
|
CoroutinePromiseAdapter $promiseAdapter,
|
||||||
Type\Schema $schema
|
Type\Schema $schema
|
||||||
): void {
|
): void {
|
||||||
|
$query = $request->getParams();
|
||||||
$contentType = $request->getHeader('content-type');
|
$contentType = $request->getHeader('content-type');
|
||||||
|
|
||||||
$maxBatchSize = App::getEnv('_APP_GRAPHQL_MAX_BATCH_SIZE', 10);
|
$maxBatchSize = App::getEnv('_APP_GRAPHQL_MAX_BATCH_SIZE', 10);
|
||||||
$maxComplexity = App::getEnv('_APP_GRAPHQL_MAX_QUERY_COMPLEXITY', 50);
|
$maxComplexity = App::getEnv('_APP_GRAPHQL_MAX_QUERY_COMPLEXITY', 50);
|
||||||
$maxDepth = App::getEnv('_APP_GRAPHQL_MAX_QUERY_DEPTH', 3);
|
$maxDepth = App::getEnv('_APP_GRAPHQL_MAX_QUERY_DEPTH', 3);
|
||||||
|
@ -121,14 +121,14 @@ function executeRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$debugFlags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
|
$flags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
|
||||||
$validations = GraphQL::getStandardValidationRules();
|
$validations = GraphQL::getStandardValidationRules();
|
||||||
$validations[] = new QueryComplexity($maxComplexity);
|
$validations[] = new QueryComplexity($maxComplexity);
|
||||||
$validations[] = new QueryDepth($maxDepth);
|
$validations[] = new QueryDepth($maxDepth);
|
||||||
|
|
||||||
if (App::isProduction()) {
|
if (App::isProduction()) {
|
||||||
$validations[] = new DisableIntrospection();
|
$validations[] = new DisableIntrospection();
|
||||||
$debugFlags = DebugFlag::NONE;
|
$flags = DebugFlag::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$promises = [];
|
$promises = [];
|
||||||
|
@ -147,9 +147,9 @@ function executeRequest(
|
||||||
$wg = new WaitGroup();
|
$wg = new WaitGroup();
|
||||||
$wg->add();
|
$wg->add();
|
||||||
$promiseAdapter->all($promises)->then(
|
$promiseAdapter->all($promises)->then(
|
||||||
function (array $results) use (&$output, &$wg, $debugFlags) {
|
function (array $results) use (&$output, &$wg, $flags) {
|
||||||
try {
|
try {
|
||||||
$output = processResult($results, $debugFlags);
|
$output = processResult($results, $flags);
|
||||||
} finally {
|
} finally {
|
||||||
$wg->done();
|
$wg->done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,12 @@ class Swagger2 extends Format
|
||||||
|
|
||||||
$bodyRequired = [];
|
$bodyRequired = [];
|
||||||
|
|
||||||
foreach ($route->getParams() as $name => $param) { // Set params
|
$parameters = \array_merge(
|
||||||
|
$route->getParams(),
|
||||||
|
$route->getLabel('sdk.parameters', []),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($parameters as $name => $param) { // Set params
|
||||||
/** @var \Utopia\Validator $validator */
|
/** @var \Utopia\Validator $validator */
|
||||||
$validator = (\is_callable($param['validator'])) ? call_user_func_array($param['validator'], $this->app->getResources($param['injections'])) : $param['validator'];
|
$validator = (\is_callable($param['validator'])) ? call_user_func_array($param['validator'], $this->app->getResources($param['injections'])) : $param['validator'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue