# \[ANN\] Announcing GraphQLGen.jl

**URL:** <https://discourse.julialang.org/t/ann-announcing-graphqlgen-jl/76326>\
**Category:** Package Announcements\
**Created:** [February 13, 2022, 3:19am UTC](https://discourse.julialang.org/t/ann-announcing-graphqlgen-jl/76326 "2022-02-13T03:19:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![domluna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domluna/32/18536_2.png) [@domluna](https://discourse.julialang.org/u/domluna)\
**Post date:** [February 13, 2022, 3:19am UTC](https://discourse.julialang.org/t/ann-announcing-graphqlgen-jl/76326/1 "2022-02-13T03:19:00Z")

</div>

GraphQLGen.jl is a package for generating Julia structs/functions from a GraphQL schema.

[Example](https://github.com/domluna/GraphQLGen.jl/tree/main/example)

## Quick Start

```julia
# Generate julia files in the GraphQLAPI directory based off all the files found in
# the schemas directory.
# 
# NOTE: You should do one call for all schema files rather than N seperate calls.
julia> GraphQLGen.generate("GraphQLAPI", "schemas/")

```

Now you’ll have two files:

- `graphqlgen_types.jl`: contains all the GraphQL types
- `graphqlgen_functions.jl`: contains all the GraphQL functions (mutations, queries, subscriptions). The intended use of these functions at the moment is to create easily create queries and variables such that they can be easily serialized for an HTTP request.

You can import and use these types and functions however you wish but note **the `StructTypes` dependency is REQUIRED since various functions were generated so the types are automatically compatible with `StructTypes`.**

## Codegen Peculiarities

Types may be ordered differently in the Julia file than the schema file. This is because  
the Julia types must be ordered by usage. For example, if struct A uses struct B in a field  
then B must appear before A in Julia code. This is also why all schema files should be parsed  
all together. If there are types which reference eachother across files and code is generated  
for each file separately, then the codegen can’t ensure they will be ordered correctly.

If there is a cycle then the types of the affected fields will be dropped altogether to ensure  
they are not referenced out of turn.
