1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::{
    type_renderer::{render_input_types, render_output_type},
    DmmfInputField, DmmfOutputField, RenderContext,
};
use schema::{InputField, InputType, OutputField, ScalarType};

pub(super) fn render_input_field<'a>(input_field: &InputField<'a>, ctx: &mut RenderContext<'a>) -> DmmfInputField {
    let type_references = render_input_types(input_field.field_types(), ctx);
    let nullable = input_field
        .field_types()
        .iter()
        .any(|typ| matches!(typ, InputType::Scalar(ScalarType::Null)));

    DmmfInputField {
        name: input_field.name.to_string(),
        input_types: type_references,
        is_required: input_field.is_required(),
        is_nullable: nullable,
        deprecation: None,
    }
}

pub(super) fn render_output_field<'a>(field: &OutputField<'a>, ctx: &mut RenderContext<'a>) -> DmmfOutputField {
    let rendered_inputs = field
        .arguments()
        .iter()
        .map(|arg| render_input_field(arg, ctx))
        .collect();
    let output_type = render_output_type(field.field_type(), ctx);

    let output_field = DmmfOutputField {
        name: field.name().clone().into_owned(),
        args: rendered_inputs,
        output_type,
        is_nullable: field.is_nullable,
        deprecation: None,
    };

    ctx.add_mapping(field.name().clone().into_owned(), field.query_info());

    output_field
}