我需要在应用程序中发表评论。这已实施并且运行良好。现在,我有一个附加要求,即要上传照片和评论。因此,我在应用程序中实现了摄像头功能,现在将图像URI发送到GraphQL API。我已经在elixir中重构了架构和类型。但是,达到服务等级后,这些参数以某种方式消失了。
comment.ex
defmodule MyApp.Comment do
use MyApp.Schema
schema "comments" do
field :art_id , :string
field :body , :string
field :image_url , :string
field :image_name , :string
belongs_to :user , User
timestamps()
end
@optional_attributes ~w(body art_id image_url image_name)a
def changeset(%Comment{} = schema, params) do
schema
|> cast(params, @optional_attributes)
|> validate_required(@required_attributes)
end
end
schema.ex包含:
field :create_comment, :comment do
arg :art_id, non_null(:string)
arg :base64_image, :string
arg :image_name, :string
arg :body, :string
middleware RequireAuth
resolve &CommentService.create_comment/2
middleware HandleErrors
end
types.ex
object :comment do
field :id , :id
field :art_id , :string
field :body , :string
field :image_name , :string
field :image_url , :image_url
field :user , :user do
resolve &UserResolver.resolve/2
end
end
scalar :image_url, description: "S3 image url" do
serialize fn(arg) ->
{:ok, url} = MyApp.FileService.get_object_url(Application.get_env(:ex_aws, :bucket), arg)
url
end
end
在我的本地服务器上的日志:
[信息] POST / api / graphql
[debug] QUERY OK source =“ users” db = 1.6ms
选择u0。“ id”,u0。“ email”,u0。“ fb_id”,u0。“全名”,u0。“ avatar_url”,u0。“密码摘要”,u0。“ email_confirmed_at”,u0。“ insertted_at”,u0 。“ updated_at”来自“用户”,如u0在哪里(u0。“ id” = $ 1)[1]
[调试]苦艾架构= MyApp.API.Schema变量=%{ “artid的数据类型”=> “逗号2005-06”, “base64Image”=>“数据:图像/ JPEG; BASE64,/ 9J / 4QMMRXhpZgAASUkqAAgAAAA3ADIBAgAUAAAAogIAAA8BAgAKAAAAtgIAAAEBAwABAAAAIAoAABABAgAIAAAAwAIAAAmSAwABAAAAEAAAAAiSAwABAAAAAAAAAAqkAwABAAAAAQAAAAikAwABAAAAAAAAAAmkAwABAAAAAAAAAAABAwABAAAAmAcAABIBAwABAAAAAAAAAAeSAwABAAAA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DblxnHUGmFyKIlVIX8aeuSc7jRtzinoSgIwKBXLNtIixbWAOfamyOEPHeokB6kUlwVWEux4FAiSbyfL3bxuPQ5 / Soy3GM / jWbLOqo0jvtUdSTVYagzsQjEsTge9A0jUeVFnwoB4 + 8PWrSanbrJl8rxWeIWTJOB681S1lwsDoq7s4yfSgV7FfVdUF3fGW2un8pRwqngjNWbO6ubmQCOOQlQPm2kgVzUTWtkpaWUKFPU + / AT / wrq989tJ5UUYtw / yNklmPcH0HpQTeysT6jqS / aUtrqYA4yAv + NYt6bK6vYkiRVcD5Gc4ye9WtPk0uyupb7VZfmJLYPzDr6Vj3982u6uf7Nt / s8UY8sykYO3sQKBppEPjDUotKvYmvb5pI9oIQtk / SM + IfEltqemx2mjRqshUZlMfU46DPrzXE6rai28QrFrt817hgThj868ds8V2Hh6KK / MT6Pbl4j8sZCkAD8enemkJaaFO + 8M6rDoEVxdaw7Ip8zyA3C + 3vXMT6naWEZjt1V5TyechT6n1ru / Fj31pYJb3e1bfvyPlz34rz / xhP4b0zQkjtYIri / Y / IYj949eT + I96d + 5Wm1i74F0uTUr5726uxFCpKj5wGY + O + nT8aj8T69ovhfV2tcyTbR83R8Z989q4zw1qniuO5ebT4VigZvL2Sp0zySM / zqWN9KjvXutbjLGNOFYk4OfTPzfShpoqcHzWTuT + L / EMniG6it7OHyVBBEmNvmE4646V0OkaBHDC7apdRsCu0qMAEdB16iuLvtX0 + 71V4NF0 + YsRxtXHmHuf9kdvwqzc2l2xRNR3PsIAUngD047UaoTjZ7WPQr2 / 0zStOBdFWB1ICx8kj2FcL4nuLfULZlVm8tX3hd + P5Vb8SsE0wkneyLlvlJ6e1ee3c2oz2zOFKRN0bJH / AOqkTfQ6Xwxqek2Qla7hEssfMb dSD6cnv71hy3Nzq2uSpptkixyybhFAhKoMc / RZ + Nc7omml7wzXTfvB8oJOSB9a7vw5eNots0scAl3IVAzg5 / CnfzGlo2iO50y8SZVvZTlflK7snA46ms3xVqVgLKOCOPzWjBIIyAnPIx0Prmi61rUbu5d7k7ctkEcYH071R1OS1ijVpiHZugA3ZFSTZp2W7LOi6nf3lkHYvHDn5QRyV5A59PQdKni8Ox3cDyNKXVSeC + Npx3 / Ssg61cpaIsRCxjJClai0 + aUGaR7hwshBI7YoCCdpJon0R38P3M5toUZphiTPX8 + uKg1VrjV78i / uCtuWwQgx8v5jNWVzKxdMntzVW8hlmwsS5btiglGsZ9FtIYotPjjFwF + fYGAJx3zWfq2q3V2xWSHy0I4Cjg8fqKoRwT2dwsdyoDEA4LZyK6CSTztPEakMWXByOlFim9blvwnqV3YWM7xbVndcxuAcrznPB6 + / + vTj4g1K71DdcXryRZysTPkE4Ayc9egpvh61nWzMTCM5J2hT0H40y1l0OzlZpooxOjHBRckmgPQk1dBcqzFfmJyD6Huay9MjaK6feQxY9M4wK0k1YallI4igKgkZ + 4fSsueGa3umEnGDwQeo9aBJXRo IPElvb2n2SNFeU7QwH3075H1rJsriWQEM21W5IH4 / nVXXFt / PWSIjd0IA5 + tRNNJ5IZHKsR1FO1yoc0Xc6 / R7jT7OyuTJaxyzS5JLAc1x89zvu5XgUoN5x82Tj3NXvtQurQRN8vHUHrTdN0ae54t4iwwcH1q1sSlYriV5diyyF5O7EdatzR2T7XEKs7AZB5xiq0elzSXTiV / L8pyrZFWo5baxuhmNLjaOGPApoUHFLlRD4hubuS1eKWVxayPuMKghQ553DHSorOwtzapO2RK2SCDU + v6q1 + uyKDyohnCk7vxrLtYH4k + 7t6c0dRqL5bs0vtSRQJbwIAEOcgdTWffwTXMuOQpHzE9a1LGKFIjIyqzY5PWmRCS9uTH GMccfSnsF0zP0iymtphl1cDknpzW3q2qXdwqW4ghREUAFGK5OOpGOvvUYtxa3Xl3DKoH4gj1puqX0VwI4bWIRqg5OeSaLArSlfcngtwtuS5DsVH5Vm3lusoYbc5G3noRTImnRijysg9R6VpL5fkBkIbjsc0dR3ktLmXZLJbNKYnZFlXY6g4DAEEA / iKdZJEt0Wk” <> ..., “身体”=> “样本图像”, “imageName”=> “1-1536824593426”}
mutation createComment($artId: String!, $body: String) {
createComment(artId: $artId, body: $body) {
id
user {
id
}
artId
body
}
}
我不确定这是怎么回事。但是,这种变异只显示了古老的观点。它不包含添加的新参数。另外,在我的解析器服务中,我仅获得art_id和body作为参数,如下所示。
%{art_id: "comma-2005-06", body: "Sample picture"}
我想念什么吗?谁能帮忙吗?
答案 0 :(得分:0)
这是由于FE中的架构定义不包含新属性。
架构定义语言
为了易于理解服务器的功能,GraphQL实现了一种人类可读的模式语法,称为其模式定义语言或“ SDL”。 SDL用于表示模式中可用的类型以及这些类型如何相互关联。
通过如下更新schema.graphql中的模式:
mutation createComment($artId: String!, $body: String, $base64Image: String, $imageName: String) {
createComment(artId: $artId, body: $body, base64Image: $base64Image, imageName: $imageName) {
...commentData
}
}
fragment commentData on Comment {
id
user {
id
fullName
}
artId
body
imageUrl
imageName
}
GraphQL API现在可以正常工作。