Skip to content

Commit

Permalink
Merge branch 'master' into fix-infinite-recursion-in-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-ramon committed Apr 10, 2023
2 parents 4188bd5 + 623f886 commit 2a6e1ff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 75 deletions.
142 changes: 69 additions & 73 deletions definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ func GetNamed(ttype Type) Named {
//
// Example:
//
// var OddType = new Scalar({
// name: 'Odd',
// serialize(value) {
// return value % 2 === 1 ? value : null;
// }
// });
//
// var OddType = new Scalar({
// name: 'Odd',
// serialize(value) {
// return value % 2 === 1 ? value : null;
// }
// });
type Scalar struct {
PrivateName string `json:"name"`
PrivateDescription string `json:"description"`
Expand Down Expand Up @@ -306,33 +305,33 @@ func (st *Scalar) Error() error {
// have a name, but most importantly describe their fields.
// Example:
//
// var AddressType = new Object({
// name: 'Address',
// fields: {
// street: { type: String },
// number: { type: Int },
// formatted: {
// type: String,
// resolve(obj) {
// return obj.number + ' ' + obj.street
// }
// }
// }
// });
// var AddressType = new Object({
// name: 'Address',
// fields: {
// street: { type: String },
// number: { type: Int },
// formatted: {
// type: String,
// resolve(obj) {
// return obj.number + ' ' + obj.street
// }
// }
// }
// });
//
// When two types need to refer to each other, or a type needs to refer to
// itself in a field, you can use a function expression (aka a closure or a
// thunk) to supply the fields lazily.
//
// Example:
//
// var PersonType = new Object({
// name: 'Person',
// fields: () => ({
// name: { type: String },
// bestFriend: { type: PersonType },
// })
// });
// var PersonType = new Object({
// name: 'Person',
// fields: () => ({
// name: { type: String },
// bestFriend: { type: PersonType },
// })
// });
//
// /
type Object struct {
Expand Down Expand Up @@ -419,7 +418,7 @@ func (gt *Object) Name() string {
return gt.PrivateName
}
func (gt *Object) Description() string {
return ""
return gt.PrivateDescription
}
func (gt *Object) String() string {
return gt.PrivateName
Expand Down Expand Up @@ -668,14 +667,12 @@ func (st *Argument) Error() error {
//
// Example:
//
// var EntityType = new Interface({
// name: 'Entity',
// fields: {
// name: { type: String }
// }
// });
//
//
// var EntityType = new Interface({
// name: 'Entity',
// fields: {
// name: { type: String }
// }
// });
type Interface struct {
PrivateName string `json:"name"`
PrivateDescription string `json:"description"`
Expand Down Expand Up @@ -779,18 +776,18 @@ func (it *Interface) Error() error {
//
// Example:
//
// var PetType = new Union({
// name: 'Pet',
// types: [ DogType, CatType ],
// resolveType(value) {
// if (value instanceof Dog) {
// return DogType;
// }
// if (value instanceof Cat) {
// return CatType;
// }
// }
// });
// var PetType = new Union({
// name: 'Pet',
// types: [ DogType, CatType ],
// resolveType(value) {
// if (value instanceof Dog) {
// return DogType;
// }
// if (value instanceof Cat) {
// return CatType;
// }
// }
// });
type Union struct {
PrivateName string `json:"name"`
PrivateDescription string `json:"description"`
Expand Down Expand Up @@ -1085,18 +1082,18 @@ func (gt *Enum) getNameLookup() map[string]*EnumValueDefinition {
// An input object defines a structured collection of fields which may be
// supplied to a field argument.
//
// Using `NonNull` will ensure that a value must be provided by the query
// # Using `NonNull` will ensure that a value must be provided by the query
//
// Example:
//
// var GeoPoint = new InputObject({
// name: 'GeoPoint',
// fields: {
// lat: { type: new NonNull(Float) },
// lon: { type: new NonNull(Float) },
// alt: { type: Float, defaultValue: 0 },
// }
// });
// var GeoPoint = new InputObject({
// name: 'GeoPoint',
// fields: {
// lat: { type: new NonNull(Float) },
// lon: { type: new NonNull(Float) },
// alt: { type: Float, defaultValue: 0 },
// }
// });
type InputObject struct {
PrivateName string `json:"name"`
PrivateDescription string `json:"description"`
Expand Down Expand Up @@ -1235,14 +1232,13 @@ func (gt *InputObject) Error() error {
//
// Example:
//
// var PersonType = new Object({
// name: 'Person',
// fields: () => ({
// parents: { type: new List(Person) },
// children: { type: new List(Person) },
// })
// })
//
// var PersonType = new Object({
// name: 'Person',
// fields: () => ({
// parents: { type: new List(Person) },
// children: { type: new List(Person) },
// })
// })
type List struct {
OfType Type `json:"ofType"`

Expand All @@ -1261,14 +1257,14 @@ func NewList(ofType Type) *List {
return gl
}
func (gl *List) Name() string {
return fmt.Sprintf("%v", gl.OfType)
return fmt.Sprintf("[%v]", gl.OfType)
}
func (gl *List) Description() string {
return ""
}
func (gl *List) String() string {
if gl.OfType != nil {
return fmt.Sprintf("[%v]", gl.OfType)
return gl.Name()
}
return ""
}
Expand All @@ -1286,12 +1282,12 @@ func (gl *List) Error() error {
//
// Example:
//
// var RowType = new Object({
// name: 'Row',
// fields: () => ({
// id: { type: new NonNull(String) },
// })
// })
// var RowType = new Object({
// name: 'Row',
// fields: () => ({
// id: { type: new NonNull(String) },
// })
// })
//
// Note: the enforcement of non-nullability occurs within the executor.
type NonNull struct {
Expand Down
4 changes: 2 additions & 2 deletions language/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func Parse(p ParseParams) (*ast.Document, error) {
return doc, nil
}

// TODO: test and expose parseValue as a public
func parseValue(p ParseParams) (ast.Value, error) {
// ParseValue parses params and returns ast value
func ParseValue(p ParseParams) (ast.Value, error) {
var value ast.Value
var sourceObj *source.Source
switch src := p.Source.(type) {
Expand Down

0 comments on commit 2a6e1ff

Please sign in to comment.