schema

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 37 Imported by: 1

README

Core API proposal

This directory contains a proposal for a complete GraphQL API for Dagger. It is written with the following goals in mind:

  1. Feature parity with Dagger 0.2
  2. Close to feature parity with Buildkit, with an incremental path to reaching full parity in the future
  3. Follow established graphql best practices
  4. Sove as many outstanding DX problems as possible

Reference

DX problems solved

Some problems in the DX that are not yet resolved, and this proposal would help solve, include:

  • Uncertainty as to how to express uploads in a graphql-friendly way (deployment, image push, git push, etc)
  • Chaining of FS operations greatly reduces verbosity, but cannot be applied all the time
  • Transitioning a script to an extension requires non-trivial refactoring, to tease apart the script-specific code from the underlying "API".
  • The API sandbox is amazing for prototyping small queries, but of limited use when multiple queries must reference each other. This is because the native code doing the stitching cannot be run by the playground, so filesystem IDs must be manually copy-pasted between queries.

Design highlights

withX and withoutX

To avoid the use of rpc-style verbs (a graphql best practice) and maximize chaining (a strength of our DX), we use the terminology withX and withoutX.

A field of the form withX returns the same object with content X added or changed.

Example:

"An empty directory with a README copied to it"
query readmeDir($readme: FileID!) {
  directory {
    withFile(source: $readme, path: "README.md") {
      id
    }
}

"An empty container with an app directory mounted into it"
query appContainer($app: DirectoryID!) {
  container {
    withMountedDirectory(source: $app, path: "/app") {
      id
    }
  }
}

A field of the form withoutX returns the same object with content X removed.

"Remove node_modules from a JS project"
query removeNodeModules($dir: DirectoryID!) {
  directory(id: $dir) {
    withoutDirectory(path: "node_modules") {
      id
    }
  }
}
Secrets

Secret handling has been simplified and made more consistent with Directory handling.

  • Secrets have an ID, and can be loaded by ID in the standard graphql manner
  • Secrets can be created in one of two ways:
    1. From an environment variable: type Environment { secret }
    2. From a file: type Directory { secret }
Embrace the llb / Dockerfile model

The Container type proposes an expansive definition of the container, similar to the Buildkit/Dockerfile model. A Container is:

  1. A filesystem state
  2. An OCI artifact which can be pulled from, and pushed to a repository at any time
  3. A persistent configuration to be applied to all commands executed inside it

This is similar to how buildkit models llb state, and how the Dockerfile language models stage state. Note that Dagger extends this model to include even mount configuration (which are scoped to exec in buildkit, but scoped to container in dagger).

Examples:

"""
Download a file over HTTP in a very convoluted way:

1. Download a base linux container
2. Install curl
3. Download the file into the container
4. Load and return the file
"""
query convolutedDownload($url: String!) {
  container {
    from(address: "index.docker.io/alpine:latest") {
      exec(args: ["apk", "add", "curl"]) {
        exec(args: ["curl", "-o", "/tmp/download", $url) {
          file(path: "/tmp/download") {
            id
         }
      }
    }
  }
}

"""
Specialize two containers from a common base
"""
query twoContainers {
  container {
    from(address: "alpine") {
      debug: withVariable(name: "DEBUG", value: "1") {
        id
        exec(args: ["env"]) {
          stdout
        }
      }
      noDebug: withVariable(name: "DEBUG", value: "0") {
        id
        exec(args: ["env"]) {
          stdout
        }
      }
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMergeTypeConflict   = errors.New("object type re-defined")
	ErrMergeFieldConflict  = errors.New("field re-defined")
	ErrMergeScalarConflict = errors.New("scalar re-defined")
)
View Source
var Cache string
View Source
var Container string
View Source
var Directory string
View Source
var File string
View Source
var HTTP string
View Source
var Host string
View Source
var Platform string
View Source
var Project string
View Source
var Query string
View Source
var Secret string
View Source
var Socket string

Functions

func ErrResolver added in v0.8.0

func ErrResolver(err error) graphql.FieldResolveFn

func PassthroughResolver added in v0.8.0

func PassthroughResolver(p graphql.ResolveParams) (any, error)

func ToResolver added in v0.8.0

func ToResolver[P any, A any, R any](f func(*core.Context, P, A) (R, error)) graphql.FieldResolveFn

ToResolver transforms any function f with a *Context, a parent P and some args A that returns a Response R and an error into a graphql resolver graphql.FieldResolveFn.

Types

type EnvVariable

type EnvVariable struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type ExecutableSchema added in v0.8.0

type ExecutableSchema interface {
	Name() string
	Schema() string
	Resolvers() Resolvers
	Dependencies() []ExecutableSchema
}

func StaticSchema added in v0.8.0

func StaticSchema(p StaticSchemaParams) ExecutableSchema

type ExposedPort added in v0.3.13

type ExposedPort struct {
	Port        int     `json:"port"`
	Protocol    string  `json:"protocol"`
	Description *string `json:"description,omitempty"`
}

NB(vito): we have to use a different type with a regular string Protocol field so that the enum mapping works.

type FieldResolvers added in v0.8.0

type FieldResolvers interface {
	Resolver
	Fields() map[string]graphql.FieldResolveFn
	SetField(string, graphql.FieldResolveFn)
}

type IDableObjectResolver added in v0.8.0

type IDableObjectResolver interface {
	FromID(id string) (any, error)
	Resolver
}

func ToIDableObjectResolver added in v0.8.0

func ToIDableObjectResolver[I ~string, T any](idToObject func(I) (*T, error), r ObjectResolver) IDableObjectResolver

type InitializeArgs

type InitializeArgs struct {
	BuildkitClient *buildkit.Client
	Platform       specs.Platform
	ProgSockPath   string
	OCIStore       content.Store
	LeaseManager   *leaseutil.Manager
	Auth           *auth.RegistryAuthProvider
	Secrets        *core.SecretStore
}

type InvalidInputError added in v0.8.0

type InvalidInputError struct {
	Err error
}

func (InvalidInputError) Error added in v0.8.0

func (e InvalidInputError) Error() string

func (InvalidInputError) Unwrap added in v0.8.0

func (e InvalidInputError) Unwrap() error

type Label added in v0.3.10

type Label struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type MergedSchemas added in v0.8.0

type MergedSchemas struct {
	// contains filtered or unexported fields
}

func New

func New(params InitializeArgs) (*MergedSchemas, error)

func (*MergedSchemas) Schema added in v0.8.0

func (s *MergedSchemas) Schema() *graphql.Schema

type ObjectResolver added in v0.8.0

type ObjectResolver map[string]graphql.FieldResolveFn

func (ObjectResolver) Fields added in v0.8.0

func (ObjectResolver) SetField added in v0.8.0

func (r ObjectResolver) SetField(name string, fn graphql.FieldResolveFn)

type Resolver added in v0.8.0

type Resolver interface {
	// contains filtered or unexported methods
}

type Resolvers added in v0.8.0

type Resolvers map[string]Resolver

type ScalarResolver added in v0.8.0

type ScalarResolver struct {
	Serialize    graphql.SerializeFn
	ParseValue   graphql.ParseValueFn
	ParseLiteral graphql.ParseLiteralFn
}

type SecretPlaintext added in v0.6.0

type SecretPlaintext string

func (SecretPlaintext) MarshalText added in v0.6.0

func (s SecretPlaintext) MarshalText() ([]byte, error)

This method ensures that the progrock vertex info does not display the plaintext.

type StaticSchemaParams added in v0.8.0

type StaticSchemaParams struct {
	Name         string
	Schema       string
	Resolvers    Resolvers
	Dependencies []ExecutableSchema
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL