Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apollo-ios-cli code generation on CocoaPods installation #2548

Merged
merged 5 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ commands:
name: Install Pod (verbose)
- run:
working_directory: Tests/CodegenCLITests/pod-install-test/Pods/Apollo/
command: ./apollo-ios-cli --version
name: Verify apollo-ios-cli binary exists
command: ./apollo-ios-cli init --schema-name NewTestSchema
name: Test init
- run:
working_directory: Tests/CodegenCLITests/pod-install-test/Pods/Apollo/
command: ./apollo-ios-cli generate
name: Test generate
save-xcodebuild-artifacts:
description: Save artifacts logs, crash reports and test results generated by xcodebuild
steps:
Expand Down
8 changes: 4 additions & 4 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@
DE2FCF4926E94D150057EA67 /* TestMockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE2FCF4826E94D150057EA67 /* TestMockTests.swift */; };
DE3484622746FF8F0065B77E /* IR+OperationBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3484612746FF8F0065B77E /* IR+OperationBuilder.swift */; };
DE363CB327640FBA001EC05B /* GraphQLJSFrontend+TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE363CB227640FBA001EC05B /* GraphQLJSFrontend+TestHelpers.swift */; };
DE3C7974260A646300D2F4FF /* dist in Resources */ = {isa = PBXBuildFile; fileRef = DE3C7973260A646300D2F4FF /* dist */; };
DE3C7B4A260A73D800D2F4FF /* AnimalKingdomAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = DE3C79A9260A6ACD00D2F4FF /* AnimalKingdomAPI.h */; settings = {ATTRIBUTES = (Public, ); }; };
DE454BA728B40D52009DC80E /* SchemaConfigurationFileGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE454BA628B40D52009DC80E /* SchemaConfigurationFileGeneratorTests.swift */; };
DE454BA928B40DA8009DC80E /* SchemaConfigurationFileGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE454BA828B40DA8009DC80E /* SchemaConfigurationFileGenerator.swift */; };
Expand Down Expand Up @@ -719,6 +718,7 @@
E6203346284F252A00A291D1 /* MockUnionsFileGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6203345284F252A00A291D1 /* MockUnionsFileGeneratorTests.swift */; };
E6203348284F25DF00A291D1 /* MockUnionsTemplateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6203347284F25DF00A291D1 /* MockUnionsTemplateTests.swift */; };
E623FD2A2797A6F4008B4CED /* InterfaceTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E623FD292797A6F4008B4CED /* InterfaceTemplate.swift */; };
E63F0C0328EE0F2A009069EA /* ApolloCodegenFrontendBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63F0C0028EE099A009069EA /* ApolloCodegenFrontendBundle.swift */; };
E64F226D28B8B3FE0011292F /* LogLevelSetter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E64F226C28B8B3FE0011292F /* LogLevelSetter.swift */; };
E64F227128B8BEE10011292F /* MockLogLevelSetter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E64F227028B8BEE10011292F /* MockLogLevelSetter.swift */; };
E64F7EB827A0854E0059C021 /* UnionTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E64F7EB727A0854E0059C021 /* UnionTemplate.swift */; };
Expand Down Expand Up @@ -1346,7 +1346,6 @@
DE2FCF4826E94D150057EA67 /* TestMockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestMockTests.swift; sourceTree = "<group>"; };
DE3484612746FF8F0065B77E /* IR+OperationBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IR+OperationBuilder.swift"; sourceTree = "<group>"; };
DE363CB227640FBA001EC05B /* GraphQLJSFrontend+TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GraphQLJSFrontend+TestHelpers.swift"; sourceTree = "<group>"; };
DE3C7973260A646300D2F4FF /* dist */ = {isa = PBXFileReference; lastKnownFileType = folder; path = dist; sourceTree = "<group>"; };
DE3C79A9260A6ACD00D2F4FF /* AnimalKingdomAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnimalKingdomAPI.h; sourceTree = "<group>"; };
DE3C79AA260A6ACD00D2F4FF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DE3C7A11260A6B9800D2F4FF /* AnimalKingdomAPI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AnimalKingdomAPI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1853,6 +1852,7 @@
E6203347284F25DF00A291D1 /* MockUnionsTemplateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUnionsTemplateTests.swift; sourceTree = "<group>"; };
E623FD292797A6F4008B4CED /* InterfaceTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterfaceTemplate.swift; sourceTree = "<group>"; };
E623FD2B2797A700008B4CED /* InterfaceTemplateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterfaceTemplateTests.swift; sourceTree = "<group>"; };
E63F0C0028EE099A009069EA /* ApolloCodegenFrontendBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloCodegenFrontendBundle.swift; sourceTree = "<group>"; };
E64F226C28B8B3FE0011292F /* LogLevelSetter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogLevelSetter.swift; sourceTree = "<group>"; };
E64F227028B8BEE10011292F /* MockLogLevelSetter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockLogLevelSetter.swift; sourceTree = "<group>"; };
E64F7EB727A0854E0059C021 /* UnionTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnionTemplate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2711,6 +2711,7 @@
9FE1E54C2588C5E000AA967E /* Frontend */ = {
isa = PBXGroup;
children = (
E63F0C0028EE099A009069EA /* ApolloCodegenFrontendBundle.swift */,
9F1A9665258F34BB00A06EEB /* GraphQLJSFrontend.swift */,
9F62DFCF2590710E00E6E808 /* GraphQLSource.swift */,
9F1A9667258F34BB00A06EEB /* GraphQLSchema.swift */,
Expand All @@ -2720,7 +2721,6 @@
9F1A9668258F34BB00A06EEB /* CompilationResult.swift */,
DE01451328A5A156000F6F18 /* ValidationOptions.swift */,
9F1A966A258F34BB00A06EEB /* JavaScriptBridge.swift */,
DE3C7973260A646300D2F4FF /* dist */,
);
path = Frontend;
sourceTree = "<group>";
Expand Down Expand Up @@ -4693,7 +4693,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DE3C7974260A646300D2F4FF /* dist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -4893,6 +4892,7 @@
DE5FD60527694FA70033EE23 /* SchemaMetadataTemplate.swift in Sources */,
DEFBBC86273470F70088AABC /* IR+Field.swift in Sources */,
9F62DFD02590710E00E6E808 /* GraphQLSource.swift in Sources */,
E63F0C0328EE0F2A009069EA /* ApolloCodegenFrontendBundle.swift in Sources */,
DE4B1E582891D5F10058D1F6 /* LinkedList.swift in Sources */,
DE5FD60B276970FC0033EE23 /* FragmentTemplate.swift in Sources */,
9BAEEBF32346DDAD00808306 /* CodegenLogger.swift in Sources */,
Expand Down

Large diffs are not rendered by default.

15 changes: 1 addition & 14 deletions Sources/ApolloCodegenLib/Frontend/GraphQLJSFrontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@ import Foundation
import JavaScriptCore

public final class GraphQLJSFrontend {
#if SWIFT_PACKAGE
private static let bundle = Bundle.module
private static let libraryURL = bundle.url(forResource: "ApolloCodegenFrontend.bundle",
withExtension: "js")!
#else
private static let bundle = Bundle(for: GraphQLJSFrontend.self)
private static let libraryURL = bundle.url(forResource: "ApolloCodegenFrontend.bundle",
withExtension: "js",
subdirectory: "dist")!
#endif

private static let librarySource = try! String.init(contentsOf: libraryURL)

private let bridge: JavaScriptBridge
private let library: JavaScriptObject

Expand All @@ -23,7 +10,7 @@ public final class GraphQLJSFrontend {
self.bridge = bridge

try bridge.throwingJavaScriptErrorIfNeeded {
bridge.context.evaluateScript(Self.librarySource, withSourceURL: Self.libraryURL)
bridge.context.evaluateScript(ApolloCodegenFrontendBundle)
}

self.library = bridge.fromJSValue(bridge.context.globalObject["ApolloCodegenFrontend"])
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/CodegenCLI/Commands/Initialize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension ApolloCodegenConfiguration {
}
},
"schemaTypes" : {
"path" : "./MySchemaName",
"path" : "./\(schemaName)",
"moduleType" : {
\(supportCocoaPods ? "\"other\"" : "\"swiftPackageManager\"") : {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query AllBooks {
books {
title
author {
name
}
}
}
14 changes: 14 additions & 0 deletions Tests/CodegenCLITests/pod-install-test/graphql/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type Book {
title: String
author: Author
}

type Author {
name: String
books: [Book]
}

type Query {
books: [Book]
authors: [Author]
}