JavaScript
7
Вклад в тег
composer require mll-lab/graphql-php-scalars
php artisan lighthouse:mutation ClassNameMutator
use App\Models\ModelName;
...
public function createOrUpdate($rootValue, array $args, GraphQLContext $context)
{
$model = ModelName::find($args['id']);
if ($model == null) {$model = new ModelName();}
$model->fill($args)->save();
$model = ModelName::select($args['field'])->find($args['id']);
return $model;
}
"A Json string with format normal Array"
scalar Mixed @scalar(class: "MLL\\GraphQLScalars\\Mixed")
...
type Mutation {
uoiModel(input: uoi! @spread): Mixed @field(resolver: "ClassNameMutator@createOrUpdate")
}
input uoi{
id: ID! //Поле таблицы в запрос
otherField: ID //Поле таблицы в запрос
field: Mixed //Поля, которые нужны в ответ, указываются в виде простого массива ["field1","field2","fieldn"]
}
mutation {
uoiModel(
input: {
id: 900003
status: 49
field: [
"id",
"status"
]
}
)
}
chartPoints.map(e => {
return e[tamestamp] = Date.parse(e.date)
}
const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("ready", async () => {
console.log("Bot Connected");
global.tdict = {};
await bot.user.setActivity("r!help", { type: "PLAYING" });
});
bot.on("voiceStateUpdate", async (before, after) => {
const author = before.member.id || after.member.id;
if (!before.channel && after.channel) {
console.log("1");
const t1 = Math.floor(Date.now() / 1000);
global.tdict[author] = t1;
} else if (before.channel && !after.channel && global.tdict.hasOwnProperty(author)) {
const t2 = Math.floor(Date.now() / 1000);
console.log("0");
console.log(t2 - global.tdict[author]);
}
});