2017-09-26 03:22:26 +08:00
|
|
|
namespace :graphql do
|
2018-11-17 06:01:16 +08:00
|
|
|
desc "Dump GraphQL schema and fragment types"
|
2017-09-26 03:22:26 +08:00
|
|
|
task schema: :environment do
|
2019-01-15 06:38:13 +08:00
|
|
|
GraphQLPostgresTimeout.do_not_wrap = true
|
|
|
|
|
2020-02-14 02:17:54 +08:00
|
|
|
File.open("#{Rails.root}/schema.graphql", "w") { |f|
|
|
|
|
f.puts CanvasSchema.to_definition
|
|
|
|
}
|
2018-11-17 06:01:16 +08:00
|
|
|
|
2020-02-14 02:17:54 +08:00
|
|
|
File.open("#{Rails.root}/app/jsx/fragmentTypes.json", "w") { |f|
|
2018-11-17 06:01:16 +08:00
|
|
|
types = CanvasSchema.execute(<<~GQL)
|
|
|
|
{
|
|
|
|
__schema {
|
|
|
|
types {
|
|
|
|
kind
|
|
|
|
name
|
|
|
|
possibleTypes {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GQL
|
|
|
|
types["data"]["__schema"]["types"].reject! { |t| t["possibleTypes"].nil? }
|
2020-02-14 02:17:54 +08:00
|
|
|
f.puts JSON.pretty_generate(types["data"])
|
|
|
|
}
|
2017-09-26 03:22:26 +08:00
|
|
|
end
|
|
|
|
end
|