Open tmk3s opened 10 months ago
mutation updateCompany($companyId: ID!, $UpdateCompanyInput: UpdateCompanyInput!){
updateCompany(id: $companyId, updateCompanyInput: $UpdateCompanyInput) {
id
name
}
}
{
"errors": [
{
"message": "Field 'updateCompany' doesn't exist on type 'Mutation'",
"locations": [
{
"line": 6,
"column": 3
}
],
"path": [
"mutation updateCompany",
"updateCompany"
],
"extensions": {
"code": "undefinedField",
"typeName": "Mutation",
"fieldName": "updateCompany"
}
},
{
"message": "Variable $companyId is declared by updateCompany but not used",
"locations": [
{
"line": 5,
"column": 1
}
],
"path": [
"mutation updateCompany"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "companyId"
}
},
{
"message": "Variable $UpdateCompanyInput is declared by updateCompany but not used",
"locations": [
{
"line": 5,
"column": 1
}
],
"path": [
"mutation updateCompany"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "UpdateCompanyInput"
}
}
]
}
↓
完成形
app/graphql/types/mutation_type.rb
# frozen_string_literal: true
module Types
class MutationType < Types::BaseObject
# TODO: remove me
field :test_field, String, null: false,
description: "An example field added by the generator"
def test_field
"Hello World"
end
field :update_comapny, mutation: Mutations::UpdateCompany
end
end
app/graphql/mutations/update_company.rb
class Mutations::UpdateCompany < Mutations::BaseMutation
argument :id, ID
argument :name, String
argument :post_code1, String
argument :post_code2, String
argument :prefecture_id, ID
argument :address, String
argument :building, String
field :errors, [String], null: false
def resolve(id:, name:, post_code1:, post_code2:, prefecture_id:, address:, building:)
company = Company.find(id)
company.assign_attributes(id:, name:, post_code1:, post_code2:, prefecture_id:, address:, building:)
if company.save
# Successful creation, return the created object with no errors
{
errors: [],
}
else
# Failed save, return the errors to the client
{
errors: company.errors.full_messages
}
end
end
end
これに対するクエリは下記のようにする
mutation updateComapny($UpdateCompanyInput: UpdateCompanyInput!){
updateComapny(input: $UpdateCompanyInput) {
errors
}
}
{
"UpdateCompanyInput": {
"id": "12",
"name": "name1",
"postCode1": "939",
"postCode2": "0627",
"prefectureId": "5",
"address": "テスト",
"building": "データ"
}
}
コマンド: ./node_modules/.bin/graphql-markdown http://0.0.0.0:8080/graphql > schema.md
Schema Types
Table of Contents
* [Query](#query) * [Mutation](#mutation) * [Objects](#objects) * [Company](#company) * [Employee](#employee) * [EmployeeAddress](#employeeaddress) * [EmployeeBank](#employeebank) * [EmployeeFamily](#employeefamily) * [EmployeePayrollGroup](#employeepayrollgroup) * [EmployeeQualification](#employeequalification) * [EmployeeSalary](#employeesalary) * [EmployeeSalaryAttendanceItem](#employeesalaryattendanceitem) * [EmployeeSalaryDeductionItem](#employeesalarydeductionitem) * [EmployeeSalaryPaymentItem](#employeesalarypaymentitem) * [UpdateCompanyPayload](#updatecompanypayload) * [Inputs](#inputs) * [UpdateCompanyInput](#updatecompanyinput) * [Enums](#enums) * [Gender](#gender) * [ItemType](#itemtype) * [Relationship](#relationship) * [Scalars](#scalars) * [Boolean](#boolean) * [ID](#id) * [Int](#int) * [String](#string)Query
Mutation
Objects
Company
会社マスタ
Employee
従業員
EmployeeAddress
従業員住所
EmployeeBank
従業員口座
EmployeeFamily
従業員家族
EmployeePayrollGroup
従業員の給与グループ
EmployeeQualification
従業員資格情報
EmployeeSalary
従業員給与
EmployeeSalaryAttendanceItem
従業員給与の勤怠項目
EmployeeSalaryDeductionItem
従業員給与の控除項目
EmployeeSalaryPaymentItem
従業員給与の支給項目
UpdateCompanyPayload
Autogenerated return type of UpdateCompany.
Inputs
UpdateCompanyInput
Autogenerated input type of UpdateCompany
Enums
Gender
ItemType
Relationship
Scalars
Boolean
Represents
true
orfalse
values.ID
Represents a unique identifier that is Base64 obfuscated. It is often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as
"VXNlci0xMA=="
) or integer (such as4
) input value will be accepted as an ID.Int
Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
String
Represents textual data as UTF-8 character sequences. This type is most often used by GraphQL to represent free-form human-readable text.