示例#1
0
func getFieldDef(
	schema typs.QLSchema,
	parentType *typs.QLObject,
	fieldName string,
) *typs.QLFieldDefinition {
	if fieldName == typs.SchemaMetaFieldDef.Name &&
		schema.GetQueryType() == parentType {
		return typs.SchemaMetaFieldDef
	}
	if fieldName == typs.TypeMetaFieldDef.Name &&
		schema.GetQueryType() == parentType {
		return typs.TypeMetaFieldDef
	}
	if fieldName == typs.TypeNameMetaFieldDef.Name {
		return typs.TypeNameMetaFieldDef
	}
	return parentType.GetFields()[fieldName]
}
示例#2
0
func getOperationRootType(
	schema typs.QLSchema,
	operation *lang.OperationDefinition,
) *typs.QLObject {
	switch operation.Operation {
	case lang.OperationQuery:
		return schema.GetQueryType()
	case lang.OperationMutation:
		murationType := schema.GetMutationType()
		if murationType == nil {
			panic(lang.NewQLError(
				"Schema is not configured for mutations",
				[]lang.INode{operation}))
		}
		return murationType
	default:
		panic(lang.NewQLError(
			"Can only execute queries and mutation",
			[]lang.INode{operation}))
	}
}
示例#3
0
文件: ast.go 项目: ng-vu/graphql-go
func TypeFromAST(schema typs.QLSchema, inputTypeAST lang.IType) typs.QLType {
	switch typ := inputTypeAST.(type) {
	case *lang.ListType:
		innerType := TypeFromAST(schema, typ.Type)
		if innerType == nil {
			return nil
		}
		return typs.NewQLList(innerType)

	case *lang.NonNullType:
		innerType := TypeFromAST(schema, typ.Type)
		if innerType == nil {
			return nil
		}
		return typs.NewQLNonNull(innerType)

	case *lang.NamedType:
		return schema.GetType(typ.Name.Value)

	default:
		throw("Must be a named type.")
		return nil
	}
}