(ns uint64, gqlSchema schema.Schema)
| 956 | } |
| 957 | |
| 958 | func (as *adminServer) resetSchema(ns uint64, gqlSchema schema.Schema) { |
| 959 | // set status as updating schema |
| 960 | mainHealthStore.updatingSchema() |
| 961 | |
| 962 | var resolverFactory resolve.ResolverFactory |
| 963 | // gqlSchema can be nil in following cases: |
| 964 | // * after DROP_ALL |
| 965 | // * if the schema hasn't yet been set even once for a non-Galaxy namespace |
| 966 | // If schema is nil then do not attach Resolver for |
| 967 | // introspection operations, and set GQL schema to empty. |
| 968 | if gqlSchema == nil { |
| 969 | resolverFactory = resolverFactoryWithErrorMsg(errNoGraphQLSchema) |
| 970 | gqlSchema, _ = schema.FromString("", ns) |
| 971 | } else { |
| 972 | resolverFactory = resolverFactoryWithErrorMsg(errResolverNotFound). |
| 973 | WithConventionResolvers(gqlSchema, as.fns) |
| 974 | // If the schema is a Federated Schema then attach "_service" resolver |
| 975 | if gqlSchema.IsFederated() { |
| 976 | resolverFactory.WithQueryResolver("_service", func(s schema.Query) resolve.QueryResolver { |
| 977 | return resolve.QueryResolverFunc(func(ctx context.Context, query schema.Query) *resolve.Resolved { |
| 978 | as.mux.RLock() |
| 979 | defer as.mux.RUnlock() |
| 980 | sch, ok := as.gqlSchemas.GetCurrent(ns) |
| 981 | if !ok { |
| 982 | return resolve.EmptyResult(query, |
| 983 | fmt.Errorf("error while getting the schema for ns %d", ns)) |
| 984 | } |
| 985 | handler, err := schema.NewHandler(sch.Schema, true) |
| 986 | if err != nil { |
| 987 | return resolve.EmptyResult(query, err) |
| 988 | } |
| 989 | data := handler.GQLSchemaWithoutApolloExtras() |
| 990 | return resolve.DataResult(query, |
| 991 | map[string]interface{}{"_service": map[string]interface{}{"sdl": data}}, |
| 992 | nil) |
| 993 | }) |
| 994 | }) |
| 995 | } |
| 996 | |
| 997 | if as.withIntrospection { |
| 998 | resolverFactory.WithSchemaIntrospection() |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | resolvers := resolve.New(gqlSchema, resolverFactory) |
| 1003 | as.gqlServer.Set(ns, as.getGlobalEpoch(ns), resolvers) |
| 1004 | |
| 1005 | // reset status to up, as now we are serving the new schema |
| 1006 | mainHealthStore.up() |
| 1007 | } |
| 1008 | |
| 1009 | func (as *adminServer) lazyLoadSchema(namespace uint64) error { |
| 1010 | // if the schema is already in memory, no need to fetch it from disk |
no test coverage detected