Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- main
paths:
- "docs/**"
- "core/schema/**"
- '.github/workflows/deploy-docs.yml'

# Allows you to run this workflow manually from the Actions tab
Expand Down
1 change: 1 addition & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Generated files
.docusaurus
.cache-loader
/static/api/reference

# Misc
.DS_Store
Expand Down
20 changes: 20 additions & 0 deletions website/docs-graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# GraphQL API Documentation

## Context

We chose to use `spectaql` as a quick way to generate a static HTML webpage for our GraphQL API reference, because it generates documentation based on a GraphQL schema.
For generating documentation based on a schema, `spectaql` uses [Handlebars](https://handlebarsjs.com/) and [Microfiber](https://www.npmjs.com/package/microfiber).

In order to tailor the documentation to our needs, we have to override the current styling and data produced from the schema.

## Examples Generation

The examples are rendered with `spectaql` with the use of [helpers](https://github.com/anvilco/spectaql/tree/1c125e0c735f354337b18c4bd773759c4e65075b/src/themes/default/helpers) that live in the default theme. Helpers are a core concept in Handlebars.

The examples live in the [`./data/examples`](./data/examples/) folder and are read at the time of generation with a script that lives in [`./custom-theme/data/index.js`](`./custom-theme/data/index.js`).

The script does not fail if there is a missing example for a given query, but it outputs the results to the console with a warning.

## Introduction Content

To modify the content in the introduction section, modify the info field in [the configuration file](./config.yml).
25 changes: 25 additions & 0 deletions website/docs-graphql/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://github.com/anvilco/spectaql/blob/main/config-example.yml
# https://www.useanvil.com/blog/engineering/building-a-spectaql-theme-for-your-graphql-documentation/

spectaql:
logoFile: ../website/static/img/dagger-logo-dark.png
faviconFile: ../website/static/img/favicon.png
themeDir: ./docs-graphql/custom-theme/

introspection:
removeTrailingPeriodFromDescriptions: false
schemaFile: ../core/schema/*.graphqls
fieldExpansionDepth: 1
metadatas: true
hideMutationsWithUndocumentedReturnType: false
hideUnusedTypes: false

extensions:
graphqlScalarExamples: true

info:
title: Dagger GraphQL API Reference
# x-introItems:
# - title: Welcome!
# description: We are using a GraphQL server as the API to interact with our engine. This allows us to make interoperation between programming languages possible.
x-url: https://api.dagger.cloud/playgrounds
104 changes: 104 additions & 0 deletions website/docs-graphql/custom-theme/data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* This is the data source entrypoint for handlebars.
*
* From the speactaql docs, this API is experimental, so
* it may break with future releases.
*
* This script takes the output from Microfiber, a tool
* that parses introspection schemas or .gql files and
* outputs the results in a friendly manner.
*
*/

const { Microfiber: IntrospectionManipulator } = require('microfiber')
const fs = require('fs');
const path = require('path')
const chalk = require('chalk')

const examplesPath = path.resolve(`${__dirname}/../../data/examples`);

console.log("Test")

function sortByName(a, b) {
if (a.name > b.name) {
return 1
}
if (a.name < b.name) {
return -1
}

return 0
}

function getExamplesByName(name) {
try {
console.log(chalk.blue(`Found example to be rendered for ${name}`))
let content = fs.readFileSync(path.resolve(`${examplesPath}/queries/${name}/gql.md`), 'utf8')
console.log(chalk.blue(`Rendering successful.`))
return [content]
} catch(err) {
console.log(chalk.red(`Error processing the example for ${name}.`), chalk.red(err))
}
}

module.exports = ({
// The Introspection Query Response after all the augmentation and metadata directives
// have been applied to it
introspectionResponse,
// All the options that are specifically for the introspection related behaviors, such a this area.
introspectionOptions,
// A GraphQLSchema instance that was constructed from the provided introspectionResponse
graphQLSchema: _graphQLSchema,
// All of the SpectaQL options in case you need them for something.
allOptions: _allOptions,
}) => {
const introspectionManipulator = new IntrospectionManipulator(
introspectionResponse,
// microfiberOptions come from converting some of the introspection options to a corresponding
// option for microfiber via the `src/index.js:introspectionOptionsToMicrofiberOptions()` function
introspectionOptions?.microfiberOptions,
)

const queryType = introspectionManipulator.getQueryType()
const normalTypes = introspectionManipulator.getAllTypes({
includeQuery: false,
includeMutation: false,
includeSubscription: false,
})

return [
// The idea is to return an Array of Objects with the following structure:
{
// The name for this group of items wherever it will be displayed
name: 'Queries',
makeContentSection: true,
items: queryType.fields
.map((query) => ({
...query,
// What is this thing? Pick one:
//
// Is this item a Query?
isQuery: true,
// Is this item a Mutation?
isMutation: false,
// Is this item a Subscription?
isSubscription: false,
// Is this item a Type?
isType: false,
// Get all examples for the query and return as array
examples: getExamplesByName(query.name)
}))
.sort(sortByName),
},
{
name: 'Types',
makeContentSection: true,
items: normalTypes
.map((type) => ({
...type,
isType: true,
}))
.sort(sortByName),
},
].filter(Boolean)
}
135 changes: 135 additions & 0 deletions website/docs-graphql/custom-theme/stylesheets/custom.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// The default theme will put nothing in here, but it will be imported in
// "main.scss", allowing users to specify it in their custom theme to adjust the
// deafult theme without losing updates to the "core" SCSS.

// You can override variables and styles in your custom.scss file. All support
// variables are shown below.

//////////////////
// Structural variables:
//////////////////
//
// $max-content-width: 88em;
// $drawer-size: 250px;
// $drawer-size-desktop-large: 300px;
//
// $content-padding: 20px;
//
// $sidebar-top: 0px;
// $sidebar-padding: $content-padding;
// $sidebar-background: #fff;
//
// $overlay-background: rgba(0, 0, 0, 0.5);
// $overlay-background-hidden: rgba(0, 0, 0, 0);
//
// $code-background: #ccc;
//
// $size-tablet: 32em;
// $size-desktop: 48em;
// $size-desktop-large: 64em;
//
// // Below this size, the sidebar will be a mobile-style drawer
// $size-sidebar-break: $size-desktop;
//
// // Below this size, the content will stack
// $size-content-break: $size-desktop;
//
// // This comes from the value passed in the config
// $logo-max-height: getLogoMaxHeightPx();
// $logo-height: getLogoHeightPx();
//
// // In case there is a navbar. getScrollOffset if a function defined in the grunt
// // config file
// $scroll-offset: getScrollOffset();


//////////////////
// Style variables
//////////////////
//
$font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
// $font-family-monospaced: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
// $text-color: red;
// $text-color-subtle: #999999;
// $link-color: #0298bf;
// $link-color-hover: #0182a2;
// $background: white;
// $border-color: #d8d8d8;
// $border-color-subtle: #e0e0e0;
// $border-size-thick: 2px;
// $border-size-thin: 1px;
//
// $background-error: #fed7d8;
// $text-color-error: #c60609;
//
// $line-height: 1.6;
// $line-height-heading: 1.2;
//
// $font-size: 16px;
// $font-size-mobile: 14px;
//
// $font-size-large-heading: 2.25em;
// $font-size-large-heading-mobile: 1.72em;
// $font-size-small: .875em;
// $font-size-code: $font-size-small;
// $font-size-small-heading: .875em;
// $font-size-example-heading: .75em;
//
// $padding-code-block: 15px $content-padding;
// $font-size-code-block: .82em;
// $text-color-code-block: white;
// $background-code-block: #222222;
// $background-code-block-heading: #000000;
// $line-height-code-block: 1.4;
//
// $container-padding-mobile: $content-padding;
// $container-padding-tablet: 30px;
// $container-padding-desktop: 50px;
//
// $container-padding-operation: 60px;
//
// $background-arguments: #fafbfc;


// Copy Docs Button
.operation-example {
a {
background: #3D66FF;
color: white !important;
font-size: 1rem;
font-style: normal;
font-weight: 700;
line-height: 1;
letter-spacing: 0em;
text-align: left;
padding: 0.625rem 1.5rem;
border: 0;
border-radius: 50px;
transition: background 0.25s ease;
white-space: nowrap;

&:hover {
background: rgba($color: #3D66FF, $alpha: 0.8);
cursor: pointer;
}
}

pre {
width: fit-content;
min-width: 400px;
border-radius: 10px;
max-width: 75ch;

@media screen and (max-width: 650px) {
width: inherit;
min-width: inherit;
}
}
}


.definition.definition-scalar .doc-row .doc-copy,
.definition.definition-object .doc-row .doc-copy {
width: 100% !important;
max-width: 85ch !important;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<section id="{{./htmlId}}"
class="operation operation-{{#if isQuery}}query{{else if isMutation}}mutation{{else if isSubscription}}subscription{{else}}unknown{{/if}}"
data-traverse-target="{{./htmlId}}">
{{# unless @first }}
{{#if parentHtmlId }}
<div class="operation-group-name">
<a href="#group-{{./parentHtmlId}}">{{./parentName}}</a>
</div>
{{/if}}
{{/unless}}

<h2 class="operation-heading {{#if (and isDeprecated (not @root.info.x-hideIsDeprecated)) }}operation-deprecated{{/if}}">
{{md (codify name) stripParagraph="true"}}
</h2>

{{#if (and deprecationReason (not @root.info.x-hideDeprecationReason))}}
<div class="doc-row">
<div class="doc-copy">
<div class="doc-copy-section">
<div class="deprecation-reason">
{{ md deprecationReason stripParagraph=true }}
</div>
</div>
</div>
</div>
{{/if}}

{{#if description}}
<div class="doc-row">
<div class="doc-copy">
<div class="operation-description doc-copy-section">
<h5>Description</h5>
{{ md (interpolateReferences description) }}
</div>
</div>
</div>
{{/if}}

<div class="doc-row">
<div class="doc-copy">
{{#if response}}
<div class="operation-response doc-copy-section">
<h5>Type</h5>
<p>
{{! If it's got items, then it's an array, and we don't care about the indefiniteArticle }}
{{!-- {{#unless response.isArray }}
{{ indefiniteArticle response.underlyingType.name }}
{{/unless}} --}}
{{~ md (mdTypeLink . codify=true) stripParagraph=true }}
</p>
</div>
{{/if}}
{{>graphql/_query-or-mutation-arguments}}
</div>
</div>

<div class="doc-row">
<div class="doc-copy">
<div class="operation-example doc-copy-section">
<h5>Example</h5>
{{#each examples }}
{{md (interpolateReferences this)}}
{{/each}}
</div>
</div>
</div>
</section>
Loading