Giter Site home page Giter Site logo

Comments (4)

theobat avatar theobat commented on July 17, 2024

hey @EdmundsEcho can you try to execute:
lookupType yourSchema "RequestInput" And see what it returns ?

from graphql-api.

EdmundsEcho avatar EdmundsEcho commented on July 17, 2024

Great question. It returns Nothing...

compileQuery uses lookupType to validate the 'TypeCondition'.

-- | Validate a type condition that appears in a query.
validateTypeCondition :: Schema -> AST.TypeCondition -> Validation TypeDefinition
validateTypeCondition schema (NamedType typeCond) =
  case lookupType schema typeCond of                  <<< here
    Nothing -> throwE (TypeConditionNotFound typeCond)
    Just typeDefn -> pure typeDefn

My schema describes the DefinedInputType among other Input related objects. However, the schema does not record a inferred TypeDefinitionObject that lookupType might find.

makeSchema calls the type class DefinesTypes function getDefinedTypes :: t -> Map Name TypeDefinition.

The InputType instance of DefinesTypes points to

DefinedInputType typeDefinition -> getDefinedTypes typeDefinition

In my case the DefinedInputType typeDefinition pattern matches to:

(DefinedInputType
(InputTypeDefinitionObject 
(InputObjectTypeDefinition (Name {unName = "RequestInput"}) 
                           (InputObjectFieldDefinition (Name {unName = etc... :| [])..

The getDefinedTypes function cascade points to the following

Value type constructor :: Type
-----------------------------------------------
DefinedInputType InputTypeDefinition :: InputType ->
InputTypeDefinitionObject InputObjectTypeDefinition :: InputTypeDefinition ->
InputObjectTypeDefinition Name (NonEmpty InputObjectFieldDefinition) :: InputObjectTypeDefinition ->   <<< here
InputObjectFieldDefinition Name (AnnotatedType InputType) (Maybe DefaultValue) :: InputObjectFieldDefinition -> 
TypeNonNull :: AnnotatedType etc...

If the InputObjectTypeDefinition is used to instantiate a TypeDefinition during the compileQuery operation, the getDefinedTypes instance evaluates to mempty

TypeDefinitionInputObject InputObjectTypeDefinition ->
TypeDefinitionInputObject _ -> mempty

If only to promote some ideas, if this is what is going on, then perhaps there are two things to consider:

  1. Should the library ever combine type definitions for InputObjectTypes with the regular ObjectTypes (e.g., combined in the same Map collection)?
  2. Should the compileQuery look for valid types in two separate collections of types, one for InputObjectTypes and the other for the regular ObjectTypes?
  3. Other explanation and thus consideration?

- E

from graphql-api.

EdmundsEcho avatar EdmundsEcho commented on July 17, 2024

One last observation for this evening. In the GraphQL.Internal.Validation module the getInputTypeDefinition relies on lookupType.

-- | Ensure that a variable has a correct type declaration given a schema.
validateTypeAssertion :: Schema -> Variable -> AST.GType -> Validation (AnnotatedType InputType)
validateTypeAssertion schema var varTypeAST =
  astAnnotationToSchemaAnnotation varTypeAST <$>
  case lookupType schema varTypeNameAST of
    Nothing -> validateVariableTypeBuiltin var varTypeNameAST
    Just cleanTypeDef -> validateVariableTypeDefinition var cleanTypeDef
  where 
    varTypeNameAST = getName varTypeAST

-- | Validate a variable type which has a type definition in the schema.
validateVariableTypeDefinition :: Variable -> TypeDefinition -> Validation InputType
validateVariableTypeDefinition var typeDef = 
  case getInputTypeDefinition typeDef of 
    Nothing -> throwE (VariableTypeIsNotInputType var $ getName typeDef)
    Just value -> pure (DefinedInputType value)

Conclusion: lookupType is being relied on to retrieve both ObjectTypes and ObjectInputTypes. Based on what I outlined in the previous post, the getDefinedTypes used to populate the collection searched by lookupType does not seem to record ObjectInputTypes defined in the Schema.

from graphql-api.

EdmundsEcho avatar EdmundsEcho commented on July 17, 2024

Does the library support using variables :: InputObject, instances of hasAnnotatedInputType, in a query that gets compiled at runtime? Has anyone had success doing so? Thank you in advance. - E

from graphql-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.