예제 #1
0
 public ClientGeneratorContext(
     GeneratorExecutionContext execution,
     ILogger log,
     StrawberryShakeSettings settings,
     string filter,
     string clientDirectory,
     IReadOnlyList <string> allDocuments)
 {
     Settings        = settings;
     Filter          = filter;
     ClientDirectory = clientDirectory;
     OutputDirectory = IOPath.Combine(clientDirectory, "Generated");
     _allDocuments   = allDocuments;
     Execution       = execution;
     Log             = log;
 }
예제 #2
0
        private static bool EnsurePreconditionsAreMet(
            GeneratorExecutionContext context,
            StrawberryShakeSettings settings)
        {
            const string http       = "StrawberryShake.Transport.Http";
            const string websockets = "StrawberryShake.Transport.WebSockets";
            const string inmemory   = "StrawberryShake.Transport.InMemory";

            var usedTransports = settings.TransportProfiles
                                 .SelectMany(t => t.GetUsedTransports()).Distinct().ToList();

            if (usedTransports.Contains(TransportType.Http))
            {
                if (!EnsureDependencyExists(context, http))
                {
                    return(false);
                }
            }

            if (usedTransports.Contains(TransportType.WebSocket))
            {
                if (!EnsureDependencyExists(context, websockets))
                {
                    return(false);
                }
            }

            if (usedTransports.Contains(TransportType.InMemory))
            {
                if (!EnsureDependencyExists(context, inmemory))
                {
                    return(false);
                }
            }

            return(true);
        }
        private static bool EnsurePreconditionsAreMet(
            GeneratorExecutionContext context,
            StrawberryShakeSettings settings,
            CSharpGeneratorResult?result)
        {
            const string http       = "StrawberryShake.Transport.Http";
            const string websockets = "StrawberryShake.Transport.WebSockets";
            const string inmemory   = "StrawberryShake.Transport.InMemory";
            const string razor      = "StrawberryShake.Razor";

            if (settings.TransportProfiles.Count == 1)
            {
                StrawberryShakeSettingsTransportProfile settingsTransportProfile = settings.TransportProfiles[0];

                if (settingsTransportProfile.Default == TransportType.Http &&
                    settingsTransportProfile.Subscription == TransportType.WebSocket &&
                    settingsTransportProfile.Query == null &&
                    settingsTransportProfile.Mutation == null)
                {
                    if (!EnsureDependencyExists(context, http))
                    {
                        return(false);
                    }

                    if (result is not null &&
                        result.OperationTypes.Contains(OperationType.Subscription) &&
                        !EnsureDependencyExists(context, http))
                    {
                        return(false);
                    }

                    return(true);
                }
            }

            var usedTransports = settings.TransportProfiles
                                 .SelectMany(t => t.GetUsedTransports()).Distinct().ToList();

            if (usedTransports.Contains(TransportType.Http))
            {
                if (!EnsureDependencyExists(context, http))
                {
                    return(false);
                }
            }

            if (usedTransports.Contains(TransportType.WebSocket))
            {
                if (!EnsureDependencyExists(context, websockets))
                {
                    return(false);
                }
            }

            if (usedTransports.Contains(TransportType.InMemory))
            {
                if (!EnsureDependencyExists(context, inmemory))
                {
                    return(false);
                }
            }

            if (settings.RazorComponents)
            {
                if (!EnsureDependencyExists(context, razor))
                {
                    return(false);
                }
            }

            return(true);
        }