-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marshaling & Unmarshaling time return initial value
There was a lack of symmetry that would prevent times for being symmetrical. That is because time.Parse actually parses an RFC3339Nano implicitly, thereby allowing nanosecond resolution on unmarshaling a time. Therefore we now marshal into nanoseconds, getting more information into GraphQL times when querying for a time, and restoring the symmetry
- Loading branch information
1 parent
f4bf1f5
commit 481a4e4
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package graphql | ||
|
||
import ( | ||
"bytes" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTime(t *testing.T) { | ||
t.Run("symmetry", func(t *testing.T) { | ||
initialTime := time.Now() | ||
buf := bytes.NewBuffer([]byte{}) | ||
MarshalTime(initialTime).MarshalGQL(buf) | ||
|
||
str, err := strconv.Unquote(buf.String()) | ||
require.Nil(t, err) | ||
newTime, err := UnmarshalTime(str) | ||
require.Nil(t, err) | ||
|
||
require.True(t, initialTime.Equal(newTime), "expected times %v and %v to equal", initialTime, newTime) | ||
}) | ||
} |