package
0.8.1
Repository: https://github.com/graphql-go/graphql.git
Documentation: pkg.go.dev

# README

Go GraphQL SQL null string example

database/sql Nullstring implementation, with JSON marshalling interfaces.

To run the program, go to the directory
cd examples/sql-nullstring

Run the example
go run main.go

sql.NullString

On occasion you will encounter sql fields that are nullable, as in

CREATE TABLE persons (
    id INT PRIMARY KEY,
    name TEXT NOT NULL,
    favorite_dog TEXT -- this field can have a NULL value
)

For the struct

import "database/sql"

type Person struct {
    ID          int             `json:"id" sql:"id"`
    Name        string          `json:"name" sql:"name"`
    FavoriteDog sql.NullString  `json:"favorite_dog" sql:"favorite_dog"`
}

But graphql would render said field as an object {{ false}} or {{Bulldog true}}, depending on their validity.

With this implementation, graphql would render the null items as an empty string (""), but would be saved in the database as NULL, appropriately.

The pattern can be extended to include other database/sql null types.

# Functions

NewNullString create a new null string.
ParseLiteralNullString parses GraphQL AST value to `NullString`.
ParseNullString parses GraphQL variables from `string` to `CustomID`.
SerializeNullString serializes `NullString` to a string.

# Variables

NullableString graphql *Scalar type based of NullString.
PersonType noqa.

# Structs

NullString to be used in place of sql.NullString.
Person noqa.