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

[2.x] restore SDL download #4046

Merged
merged 4 commits into from Apr 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,8 @@
package com.apollographql.apollo.gradle.internal

import com.apollographql.apollo.compiler.parser.introspection.IntrospectionSchema
import com.apollographql.apollo.compiler.parser.introspection.toSDL
import okio.Buffer
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
Expand Down Expand Up @@ -36,7 +39,12 @@ abstract class ApolloDownloadSchemaTask : DefaultTask() {
)

schema.parentFile.mkdirs()
schema.writeText(introspection)

if (schema.extension == "json") {
schema.writeText(introspection)
} else {
IntrospectionSchema(Buffer().writeUtf8(introspection).inputStream()).toSDL(schema)
}
}

private fun List<String>.toMap(): Map<String, String> {
Expand Down
Expand Up @@ -8,6 +8,8 @@ import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThat
import org.junit.Assert.assertTrue
import org.junit.Test
import java.io.File

Expand All @@ -25,6 +27,17 @@ class DownloadSchemaTests {
}
""".trimIndent()

val sdlConfiguration = """
apollo {
service("mock") {
schemaPath = "com/example/schema.sdl"
introspection {
endpointUrl = "${mockServer.url("/").toUrl()}"
}
}
}
""".trimIndent()

@Test
fun `schema is downloaded correctly`() {

Expand All @@ -39,6 +52,19 @@ class DownloadSchemaTests {
}
}

@Test
fun `SDL schema is downloaded correctly`() {

withSimpleProject(apolloConfiguration = sdlConfiguration) { dir ->
val mockResponse = MockResponse().setBody(File("src/test/files/sdl/schema.json").readText())
mockServer.enqueue(mockResponse)

TestUtils.executeTask("downloadMockApolloSchema", dir)

assertTrue(dir.child("src", "main", "graphql", "com", "example", "schema.sdl").readText().contains("enum FeedType"))
}
}

@Test
fun `download schema is never up-to-date`() {

Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Expand Up @@ -11,7 +11,7 @@ def versions = [
javaPoet : '1.9.0',
jetbrainsAnnotations : '13.0',
junit : '4.13.2',
kotlin : '1.5.0',
kotlin : '1.5.31',
kotlinCoroutines : '1.5.0',
kotlinPoet : '1.6.0',
mockito : '1.9.5',
Expand Down
29 changes: 17 additions & 12 deletions netlify.toml
@@ -1,14 +1,19 @@
[build]
base = "docs"
publish = "docs/public"
command = "./generate-docs.sh"
ignore = "exit 0"

[build.environment]
NPM_VERSION = "6"
[context.production.environment]
PREFIX_PATHS = "true"
[context.branch-deploy.environment]
PREFIX_PATHS = "true"
[dev]
command = "npm run build"
[context.dev.environment]
SKIP_INDEXING = "false"
NODE_VERSION = "16"

[context.deploy-preview.build]
base = "docs"
ignore = "git diff --quiet HEAD^ HEAD ."
command = """\
cd ../
rm -rf monodocs
git clone https://github.com/apollographql/docs --branch main --single-branch monodocs
cd monodocs
npm i
cp -r ../docs local
DOCS_LOCAL=true npm run build \
"""
publish = "../monodocs/public"