graphql_starter/graphql/
sdl.rs

1use std::{fs, io, path::Path};
2
3use async_graphql::{ObjectType, SDLExportOptions, Schema, SubscriptionType};
4
5// Exports the GraphQL SDL to the provided path
6pub fn export_graphql_sdl<Query, Mutation, Subscription>(
7    schema: &Schema<Query, Mutation, Subscription>,
8    path: impl AsRef<Path>,
9    federation: bool,
10) -> io::Result<()>
11where
12    Query: ObjectType + 'static,
13    Mutation: ObjectType + 'static,
14    Subscription: SubscriptionType + 'static,
15{
16    if federation {
17        fs::write(path, schema.sdl_with_options(SDLExportOptions::new().federation()))?;
18    } else {
19        fs::write(path, schema.sdl())?;
20    }
21
22    Ok(())
23}