示例#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}))
	}
}