Repository: dgraph-io/dgraph
File: graphql/resolve/resolver.go (Go)

Code before:

	if r == nil {
		glog.Errorf("[%s] Call to Resolve with nil RequestResolver", reqID)
		return schema.ErrorResponse(errors.New("Internal error"), reqID)
	}

	if r.schema == nil {
		glog.Errorf("[%s] Call to Resolve with no schema", reqID)
		return schema.ErrorResponse(errors.New("Internal error"), reqID)
	}

	op, err := r.schema.Operation(gqlReq)
	if err != nil {
		return schema.ErrorResponse(err, reqID)
	}

	resp := &schema.Response{
		Extensions: &schema.Extensions{
			RequestID: reqID,
		},
	}

	if glog.V(3) {
		// don't log the introspection queries they are sent too frequently
		// by GraphQL dev tools
		if !op.IsQuery() || !strings.HasPrefix(op.Queries()[0].Name(), "__") {
			b, err := json.Marshal(gqlReq.Variables)
			if err != nil {
				glog.Infof("Failed to marshal variables for logging : %s", err)
			}
			glog.Infof("[%s] Resolving GQL request: \n%s\nWith Variables: \n%s\n",
				reqID, gqlReq.Query, string(b))
		}
	}

	// A single request can contain either queries or mutations - not both.
	// GraphQL validation on the request would have caught that error case
	// before we get here.  At this point, we know it's valid, it's passed
	// GraphQL validation and any additional validation we've added.  So here,
	// we can just execute it.
	switch {
	case op.IsQuery():
		// Queries run in parallel and are independent of each other: e.g.
		// an error in one query, doesn't affect the others.

		var wg sync.WaitGroup
		allResolved := make([]*Resolved, len(op.Queries()))

		for i, q := range op.Queries() {
			wg.Add(1)


Review comment (suggestion):
The second check in the OR block could also have compared the QueryType to make it a bit clearer. 

Code after:

	if r == nil {
		glog.Errorf("[%s] Call to Resolve with nil RequestResolver", reqID)
		return schema.ErrorResponse(errors.New("Internal error"), reqID)
	}

	if r.schema == nil {
		glog.Errorf("[%s] Call to Resolve with no schema", reqID)
		return schema.ErrorResponse(errors.New("Internal error"), reqID)
	}

	op, err := r.schema.Operation(gqlReq)
	if err != nil {
		return schema.ErrorResponse(err, reqID)
	}

	resp := &schema.Response{
		Extensions: &schema.Extensions{
			RequestID: reqID,
		},
	}

	if glog.V(3) {
		// don't log the introspection queries they are sent too frequently
		// by GraphQL dev tools
		if !op.IsQuery() ||
			(op.IsQuery() && !strings.HasPrefix(op.Queries()[0].Name(), "__")) {
			b, err := json.Marshal(gqlReq.Variables)
			if err != nil {
				glog.Infof("Failed to marshal variables for logging : %s", err)
			}
			glog.Infof("[%s] Resolving GQL request: \n%s\nWith Variables: \n%s\n",
				reqID, gqlReq.Query, string(b))
		}
	}

	// A single request can contain either queries or mutations - not both.
	// GraphQL validation on the request would have caught that error case
	// before we get here.  At this point, we know it's valid, it's passed
	// GraphQL validation and any additional validation we've added.  So here,
	// we can just execute it.
	switch {
	case op.IsQuery():
		// Queries run in parallel and are independent of each other: e.g.
		// an error in one query, doesn't affect the others.

		var wg sync.WaitGroup
		allResolved := make([]*Resolved, len(op.Queries()))

		for i, q := range op.Queries() {
			wg.Add(1)