Giter Club home page Giter Club logo

Comments (2)

kevin-carroll avatar kevin-carroll commented on August 22, 2024

After further thought the extra values in the [GraphFIeld] are not necessary. As of today, since all INPUT_OBJECT types are first created from a parameterless constructor there exists an opportunity for developer code to set any necessary values. We only then need the ability to mark fields as non-nullable when they otherwise would be due to type constraints. This is mostly around value types such as int, double etc.

While it is possible today to mark a field as required or not using the [GraphField] attribute its a bit limiting and not very intuitive.

  • [GraphField(TypeExpressions= TypeExpressions.None)]
    • Will Mark an otherwise required property (such as an int) as being not required
  • [GraphField(TypeExpressions= TypeExpressions.IsNotNullable)]
    • Will mark a nullable property (such as a reference) as being required.

Since declaring a type expression overrides what the templating engine would glean about the property return type, you run into trouble if the property is a list. You would have to redeclare the entire list structure as part of the TypeExpression field in order to maintain its correctness if you wished to apply "non-nullability" to the list.

This is exceedingly cumbersome and verbose.

Proposal (Breaking Change):

It is in error to force an value type property to be required in a query unless otherwise stated by the user.

Take a page from ASP.NET and the use of [Required] (from System.ComponentModel) for deserializing objects during rest queries. If a field is attributed with [Required]then it must be supplied. Otherwise its value will be set to whatever is the value of default(Type) is or a value supplied during the object's constructor.

This would be a breaking change in that it changes the default behavior for value type fields on INPUT_OBJECT types. However, in the spirit of conforming to ASP.NET standards and general expectations of ASP.NET developers, this change should prove better in the long run.

// assume this class is registered as an INPUT_OBJECT
public class Person
{
   Person()
   {
      this.IsHappy = true; // set a default value during object creation
      this.Child = null;
   }

   // NOT required in a query
   // Expresssion:  'String'
   // Default Value:  <null>  | as defined by default(string)
   public string FirstName { get; set; }

   // REQUIRED in a query
   // Expresssion:  'String!'
   // Default Value:  -Not defined-
   [Required]
   public string LastName { get; set; }

   // REQUIRED in a query
   // Expresssion:  'Address!'
   // Default Value:  -Not defined-
   [Required]
   public Address Address { get; set; }

   // NOT REQUIRED in a query
   // Expresssion:  'Person'
   // Default Value:  null  | as set in the constructor
   public Person Child { get; set; }

   // NOT REQUIRED in a query
   // Expresssion:  'Bool'
   // Default Value:  true  | as set in the constructor
   public bool IsHappy { get; set; }

   // NOT REQUIRED in a query
   // Expresssion:  'Int'
   // Default Value:  0  | as set by default(int)
   public int Age{  get; set; }

   // REQUIRED in a query
   // Expresssion:  'Int!'
   // Default Value:  - Not Defined -
   [Required]
   public int BirthOrder { get; set; }
}

from graphql-aspnet.

kevin-carroll avatar kevin-carroll commented on August 22, 2024

released as part of v0.12.0-beta

from graphql-aspnet.

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.