title: Golang GraphQL always returns one variable as null
body: <p>GraphQL query field post and list return all data except created_at. It always null. I check <code>GetPostBySlug</code> and <code>GetPostList</code> variables and it contain data from Postgres. Where is my mistake?</p>
  <p>model.go</p>
  <pre><code>package post
  
  type Post struct {
      Slug      string `db:&quot;slug&quot;`
      Title     string `db:&quot;title&quot;`
      Content   string `db:&quot;content&quot;`
      Author    string `db:&quot;author&quot;`
      Category  string `db:&quot;category&quot;`
      CreatedAt string `db:&quot;created_at&quot;`
      Published bool   `db:&quot;published&quot;`
  }
  </code></pre>
  <p>resolver.go</p>
  <pre><code>package post
  
  import (
      &quot;context&quot;
  
      &quot;github.com/graphql-go/graphql&quot;
  )
  
  var postType = graphql.NewObject(
      graphql.ObjectConfig{
          Name: &quot;Post&quot;,
          Fields: graphql.Fields{
              &quot;slug&quot;: &amp;graphql.Field{
                  Type: graphql.String,
              },
              &quot;title&quot;: &amp;graphql.Field{
                  Type: graphql.String,
              },
              &quot;content&quot;: &amp;graphql.Field{
                  Type: graphql.String,
              },
              &quot;category&quot;: &amp;graphql.Field{
                  Type: graphql.String,
              },
              &quot;author&quot;: &amp;graphql.Field{
                  Type: graphql.String,
              },
              &quot;created_at&quot;: &amp;graphql.Field{
                  Type: graphql.String,
              },
              &quot;published&quot;: &amp;graphql.Field{
                  Type: graphql.Boolean,
              },
          },
      },
  )
  
  var queryType = graphql.NewObject(
      graphql.ObjectConfig{
          Name: &quot;Query&quot;,
          Fields: graphql.Fields{
              &quot;post&quot;: &amp;graphql.Field{
                  Type:        postType,
                  Description: &quot;Get post by slug&quot;,
                  Args: graphql.FieldConfigArgument{
                      &quot;slug&quot;: &amp;graphql.ArgumentConfig{
                          Type: graphql.String,
                      },
                  },
                  Resolve: func(p graphql.ResolveParams) (interface{}, error) {
                      var result interface{}
  
                      slug, _ := p.Args[&quot;slug&quot;].(string)
                      result = GetPostBySlug(context.Background(), slug)
  
                      return result, nil
                  },
              },
              &quot;list&quot;: &amp;graphql.Field{
                  Type:        graphql.NewList(postType),
                  Description: &quot;Get post list&quot;,
                  Args: graphql.FieldConfigArgument{
                      &quot;limit&quot;: &amp;graphql.ArgumentConfig{
                          Type: graphql.Int,
                      },
                  },
                  Resolve: func(params graphql.ResolveParams) (interface{}, error) {
                      var result interface{}
  
                      limit, _ := params.Args[&quot;limit&quot;].(int)
                      result = GetPostList(context.Background(), limit)
  
                      return result, nil
                  },
              },
          },
      })
  
  var mutationType = graphql.NewObject(graphql.ObjectConfig{
      Name: &quot;Mutation&quot;,
      Fields: graphql.Fields{
          &quot;create&quot;: &amp;graphql.Field{
              Type:        postType,
              Description: &quot;Create new post&quot;,
              Args: graphql.FieldConfigArgument{
                  &quot;slug&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;title&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;content&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;category&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;author&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;published&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.Boolean),
                  },
              },
              Resolve: func(params graphql.ResolveParams) (interface{}, error) {
                  post := Post{
                      Slug:      params.Args[&quot;slug&quot;].(string),
                      Title:     params.Args[&quot;title&quot;].(string),
                      Content:   params.Args[&quot;content&quot;].(string),
                      Category:  params.Args[&quot;category&quot;].(string),
                      Author:    params.Args[&quot;author&quot;].(string),
                      Published: params.Args[&quot;published&quot;].(bool),
                  }
                  if err := InsertPost(context.Background(), post); err != nil {
                      return nil, err
                  }
                  return nil, nil
              },
          },
          &quot;update&quot;: &amp;graphql.Field{
              Type:        postType,
              Description: &quot;Update post&quot;,
              Args: graphql.FieldConfigArgument{
                  &quot;slug&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;title&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;content&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;category&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;author&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
                  &quot;published&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.Boolean),
                  },
              },
              Resolve: func(params graphql.ResolveParams) (interface{}, error) {
                  post := Post{}
  
                  if slug, slugOk := params.Args[&quot;slug&quot;].(string); slugOk {
                      post.Slug = slug
                  }
                  if title, titleOk := params.Args[&quot;title&quot;].(string); titleOk {
                      post.Title = title
                  }
                  if content, contentOk := params.Args[&quot;content&quot;].(string); contentOk {
                      post.Content = content
                  }
  
                  if category, categoryOk := params.Args[&quot;category&quot;].(string); categoryOk {
                      post.Category = category
                  }
  
                  if published, publishedOk := params.Args[&quot;published&quot;].(bool); publishedOk {
                      post.Published = published
                  }
  
                  if old_slug, old_slugOk := params.Args[&quot;old-slug&quot;].(string); old_slugOk {
                      if err := UpdatePost(context.Background(), post, old_slug); err != nil {
                          return nil, err
                      }
                  }
  
                  return nil, nil
              },
          },
          &quot;delete&quot;: &amp;graphql.Field{
              Type:        postType,
              Description: &quot;Delete post by slug&quot;,
              Args: graphql.FieldConfigArgument{
                  &quot;slug&quot;: &amp;graphql.ArgumentConfig{
                      Type: graphql.NewNonNull(graphql.String),
                  },
              },
              Resolve: func(params graphql.ResolveParams) (interface{}, error) {
                  slug, _ := params.Args[&quot;slug&quot;].(string)
                  if err := DeletePost(context.Background(), slug); err != nil {
                      return nil, err
                  }
                  return nil, nil
              },
          },
      },
  })
  
  var Schema, _ = graphql.NewSchema(
      graphql.SchemaConfig{
          Query:    queryType,
          Mutation: mutationType,
      },
  )
  </code></pre>
  <p>repository.go</p>
  <pre><code>package post
  
  import (
      &quot;context&quot;
      &quot;errors&quot;
      &quot;fmt&quot;
      &quot;log&quot;
      &quot;os&quot;
      &quot;time&quot;
  
      &quot;github.com/jackc/pgx/v4&quot;
      &quot;github.com/joho/godotenv&quot;
  )
  
  var (
      db      *pgx.Conn
      Info    *log.Logger
      Warning *log.Logger
      Error   *log.Logger
  )
  
  func init() {
      err := godotenv.Load(&quot;environment/.env&quot;)
      if err != nil {
          Error.Fatalf(&quot;Can't read \&quot;.env\&quot; file: %s\n&quot;, err.Error())
      }
  
      Info = log.New(os.Stdout, &quot;INFO: &quot;, log.Ldate|log.Ltime|log.Lshortfile)
      Warning = log.New(os.Stdout, &quot;WARNING: &quot;, log.Ldate|log.Ltime|log.Lshortfile)
      Error = log.New(os.Stderr, &quot;ERROR: &quot;, log.Ldate|log.Ltime|log.Lshortfile)
  
      db, err = pgx.Connect(
          context.Background(),
          fmt.Sprintf(
              &quot;postgres://%s:%s@%s:%s/%s&quot;,
              os.Getenv(&quot;POSTGRES_USER&quot;),
              os.Getenv(&quot;POSTGRES_PASSWORD&quot;),
              os.Getenv(&quot;POSTGRES_HOST&quot;),
              os.Getenv(&quot;POSTGRES_PORT&quot;),
              os.Getenv(&quot;POSTGRES_DB&quot;),
          ),
      )
      if err != nil {
          Error.Fatalf(&quot;Can't connect to database: %s\n&quot;, err.Error())
      }
  }
  
  func GetPostBySlug(ctx context.Context, slug string) (result interface{}) {
      row, err := db.Query(ctx, &quot;SELECT slug, title, content, author, category, created_at, published FROM posts WHERE slug=$1 LIMIT 1&quot;, slug)
      if err != nil {
          Warning.Printf(&quot;GetPostBySlug query: %v\n&quot;, err.Error())
          return err
      }
  
      var post Post
  
      for row.Next() {
          var dateTime time.Time
  
          err = row.Scan(&amp;post.Slug, &amp;post.Title, &amp;post.Content, &amp;post.Author, &amp;post.Category, &amp;dateTime, &amp;post.Published)
          if err != nil {
              Warning.Printf(&quot;Row scan: %v\n&quot;, err.Error())
              return nil
          }
  
          post.CreatedAt = dateTime.Format(&quot;02.01.2006&quot;)
      }
  
      return post
  }
  
  func GetPostList(ctx context.Context, limit int) (result interface{}) {
      var post Post
      var posts []Post
  
      var dateTime time.Time
  
      rows, err := db.Query(ctx, &quot;SELECT slug, title, content, author, category, created_at, published FROM posts LIMIT $1&quot;, limit)
      if err != nil {
          Warning.Printf(&quot;GetPostList query: %v\n&quot;, err.Error())
          return err
      }
  
      for rows.Next() {
          err = rows.Scan(&amp;post.Slug, &amp;post.Title, &amp;post.Content, &amp;post.Author, &amp;post.Category, &amp;dateTime, &amp;post.Published)
          if err != nil {
              Warning.Printf(&quot;Row scan: %v\n&quot;, err.Error())
              return nil
          }
  
          post.CreatedAt = dateTime.Format(&quot;02.01.2006&quot;)
  
          posts = append(posts, post)
      }
  
      return posts
  }
  
  func InsertPost(ctx context.Context, post Post) error {
      if SlugExists(ctx, post.Slug) {
          Warning.Printf(&quot;Slug \&quot;%s\&quot; already exists!\n&quot;, post.Slug)
          return errors.New(&quot;slug already exists&quot;)
      }
  
      _, err := db.Exec(
          ctx,
          &quot;INSERT INTO posts (slug, title, content, author, category, created_at, published) VALUES ($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, $6)&quot;,
          post.Slug, post.Title, post.Content, post.Author, post.Category, post.Published,
      )
      if err != nil {
          Warning.Printf(&quot;InsertPost exec query: %v\n&quot;, err.Error())
          return err
      }
  
      return nil
  }
  
  func SlugExists(ctx context.Context, slug string) bool {
      row, err := db.Query(ctx, &quot;SELECT slug FROM posts WHERE slug=$1 LIMIT 1&quot;, slug)
      if err != nil {
          Error.Fatalf(&quot;SlugExists query: %v\n&quot;, err.Error())
      }
  
      var slug_exists string
  
      for row.Next() {
          err = row.Scan(&amp;slug_exists)
          if err != nil {
              Error.Fatalf(&quot;Row scan: %v\n&quot;, err.Error())
          }
      }
  
      return slug_exists != &quot;&quot;
  }
  
  func UpdatePost(ctx context.Context, post Post, old_slug string) error {
      _, err := db.Exec(
          ctx,
          &quot;UPDATE posts SET slug=$1, title=$2, content=$3, author=$4, category=$5, published=$6 WHERE slug=$7&quot;,
          post.Slug, post.Title, post.Content, post.Author, post.Category, post.Published, old_slug,
      )
      if err != nil {
          Warning.Printf(&quot;UpdatePost exec query: %v\n&quot;, err.Error())
          return err
      }
  
      return nil
  }
  
  func DeletePost(ctx context.Context, slug string) error {
      _, err := db.Exec(ctx, &quot;DELETE FROM posts WHERE slug=$1&quot;, slug)
      if err != nil {
          Warning.Printf(&quot;DeletePost exec query: %v\n&quot;, err.Error())
          return err
      }
  
      return nil
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/wccZQ.png" rel="nofollow noreferrer">query post result</a></p>
  <p><a href="https://i.stack.imgur.com/YxBB5.png" rel="nofollow noreferrer">query list result</a></p>