Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type parameters to allow for schema type constraints #18

Closed
jamesmacaulay opened this issue May 9, 2017 · 2 comments
Closed

Add type parameters to allow for schema type constraints #18

jamesmacaulay opened this issue May 9, 2017 · 2 comments
Milestone

Comments

@jamesmacaulay
Copy link
Owner

Concurrently with #17, we should investigate adding phantom type parameters to ObjectType and SelectionSpec representing a type marker corresponding to a type from the target schema:

type ObjectType schemaType
    = ObjectType

type SelectionSpec schemaType selectionType result vars
    = SelectionSpec AST.Selection (AST.SelectionSet -> Decoder result) (List (Variable vars)) (List AST.FragmentDefinitionInfo)

This would allow each module that provides helper functions for an object/interface/union type to constrain those functions such that they only operate in correct ways according to the source schema. For example:

module Schema.Types.User exposing (..)

import GraphQL.Request.Builder exposing (..)
import Schema.Types as Types

name : SelectionSpec Types.User String vars
name =
    field "name" [] string


projects :
    List ( String, Arg.Value vars )
    -> ValueSpec NonNull (ObjectType Types.Project) result vars
    -> SelectionSpec Types.User (List result) vars
projects args projectSpec =
    field "projects" args (list projectSpec)
@jamesmacaulay jamesmacaulay added this to the 2.0 milestone May 9, 2017
@jamesmacaulay jamesmacaulay self-assigned this May 9, 2017
@jamesmacaulay jamesmacaulay removed their assignment May 9, 2017
@jamesmacaulay
Copy link
Owner Author

jamesmacaulay commented Oct 14, 2017

Note: instead of adding this parameter to ObjectType, it may be preferable to add it to ValueSpec, and allow it for non-object types as well.

@jamesmacaulay jamesmacaulay changed the title Add type parameter to ObjectType to allow schema type constraints Add type parameter to allow schema type constraints Oct 14, 2017
@jamesmacaulay jamesmacaulay changed the title Add type parameter to allow schema type constraints Add type parameters to allow schema type constraints Oct 14, 2017
@jamesmacaulay jamesmacaulay changed the title Add type parameters to allow schema type constraints Add type parameters to allow for schema type constraints Oct 14, 2017
@jamesmacaulay
Copy link
Owner Author

Closing for the foreseeable future along with #17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant