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

Introduce "filesystem" sourceSet and use okio 3.9.0 #5719

Merged
merged 3 commits into from
Mar 14, 2024
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
17 changes: 10 additions & 7 deletions build-logic/src/main/kotlin/Mpp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ fun Project.configureMpp(
private fun KotlinMultiplatformExtension.configureSourceSetGraph() {
applyDefaultHierarchyTemplate {
group("common") {
group("concurrent") {
group("native") {
group("apple")
}
group("jvmCommon") {
withJvm()
withAndroidTarget()
group("filesystem") {
group("concurrent") {
group("native") {
group("apple")
}
group("jvmCommon") {
withJvm()
withAndroidTarget()
}
}
group("js")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ktor = "2.3.7"
moshix = "0.14.1"
node-fetch = "2.6.7"
node-ws = "8.14.2"
okio = "3.6.0"
okio = "3.9.0"
okhttp = "4.11.0"
rx-android = "2.0.1"
rx-java2 = "2.2.21"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@file:JvmMultifileClass
@file:JvmName("DefaultUploadKt")
package com.apollographql.apollo3.api

import okio.BufferedSink
import okio.ByteString
import okio.FileSystem
import okio.Path
import okio.buffer
import okio.use
import okio.utf8Size
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* A default [Upload] that can upload from a wide variety of content
Expand Down Expand Up @@ -91,14 +91,3 @@ class DefaultUpload internal constructor(
}
}

fun Path.toUpload(contentType: String, fileSystem: FileSystem = systemFileSystem): Upload {
return DefaultUpload.Builder()
.content { sink ->
fileSystem.openReadOnly(this).use {
sink.writeAll(it.source().buffer())
}
}
.contentType(contentType)
.contentLength(fileSystem.metadata(this).size ?: -1L)
.build()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:JvmMultifileClass
@file:JvmName("DefaultUploadKt")
package com.apollographql.apollo3.api

import okio.FileSystem
import okio.Path
import okio.SYSTEM
import okio.buffer
import okio.use
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

fun Path.toUpload(contentType: String, fileSystem: FileSystem = FileSystem.SYSTEM): Upload {
return DefaultUpload.Builder()
.content { sink ->
fileSystem.openReadOnly(this).use {
sink.writeAll(it.source().buffer())
}
}
.contentType(contentType)
.contentLength(fileSystem.metadata(this).size ?: -1L)
.build()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.apollographql.apollo3.api

import okio.FileSystem
import okio.SYSTEM

internal actual val systemFileSystem: FileSystem
get() = FileSystem.SYSTEM

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.apollographql.apollo3.api
import okio.FileSystem

internal actual val systemFileSystem: FileSystem
get() = throw IllegalStateException("There is no SYSTEM filesystem on JS")
get() = throw IllegalStateException("There is no SYSTEM filesystem on wasmJs")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import com.apollographql.apollo3.ast.internal.LexerException
import com.apollographql.apollo3.ast.internal.Parser
import com.apollographql.apollo3.ast.internal.ParserException
import com.apollographql.apollo3.ast.internal.validateSchema
import com.apollographql.apollo3.ast.introspection.toGQLDocument
import com.apollographql.apollo3.ast.introspection.toIntrospectionSchema
import okio.BufferedSource
import okio.Path
import okio.buffer
import okio.use
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
Expand Down Expand Up @@ -137,18 +133,6 @@ fun String.toGQLSelections(options: ParserOptions = ParserOptions.Default): List
return parseAsGQLSelections(options).getOrThrow()
}

fun Path.parseAsGQLDocument(options: ParserOptions = ParserOptions.Default): GQLResult<GQLDocument> {
return HOST_FILESYSTEM.source(this).buffer().parseAsGQLDocument(filePath = toString(), options = options)
}

fun Path.toGQLDocument(options: ParserOptions = ParserOptions.Default, allowJson: Boolean = false): GQLDocument {
return if (allowJson && name.endsWith(".json")) {
toIntrospectionSchema().toGQLDocument()
} else {
parseAsGQLDocument(options).getOrThrow()
}
}

/**
* Parses the source to a [GQLDocument], validating the syntax but not the contents of the document.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@ import com.apollographql.apollo3.ast.GQLStringValue
import com.apollographql.apollo3.ast.GQLType
import com.apollographql.apollo3.ast.GQLUnionTypeDefinition
import com.apollographql.apollo3.ast.GQLValue
import com.apollographql.apollo3.ast.HOST_FILESYSTEM
import com.apollographql.apollo3.ast.Schema
import com.apollographql.apollo3.ast.SourceLocation
import com.apollographql.apollo3.ast.parseAsGQLValue
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import okio.Buffer
import okio.BufferedSource
import okio.ByteString.Companion.decodeHex
import okio.Path
import okio.buffer
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

Expand Down Expand Up @@ -91,14 +87,6 @@ fun BufferedSource.toIntrospectionSchema(filePath: String? = null): Introspectio

fun String.toIntrospectionSchema(): IntrospectionSchema = Buffer().writeUtf8(this).toIntrospectionSchema()

@ApolloExperimental
fun Path.toIntrospectionSchema(): IntrospectionSchema {
return HOST_FILESYSTEM
.source(this)
.buffer()
.toIntrospectionSchema(toString())
}

/**
* Parses the [RSchema] into a [GQLDocument]
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.apollographql.apollo3.ast

import okio.FileSystem
import okio.SYSTEM

internal actual val HOST_FILESYSTEM: FileSystem
get() = FileSystem.SYSTEM
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:JvmMultifileClass
@file:JvmName("ApolloParser")

package com.apollographql.apollo3.ast

import com.apollographql.apollo3.ast.introspection.toGQLDocument
import com.apollographql.apollo3.ast.introspection.toIntrospectionSchema
import okio.Path
import okio.buffer
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

fun Path.parseAsGQLDocument(options: ParserOptions = ParserOptions.Default): GQLResult<GQLDocument> {
return HOST_FILESYSTEM.source(this).buffer().parseAsGQLDocument(filePath = toString(), options = options)
}

fun Path.toGQLDocument(options: ParserOptions = ParserOptions.Default, allowJson: Boolean = false): GQLDocument {
return if (allowJson && name.endsWith(".json")) {
toIntrospectionSchema().toGQLDocument()
} else {
parseAsGQLDocument(options).getOrThrow()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@file:JvmMultifileClass
@file:JvmName("Introspection")

package com.apollographql.apollo3.ast.introspection

import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.ast.HOST_FILESYSTEM
import okio.Path
import okio.buffer
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

@ApolloExperimental
fun Path.toIntrospectionSchema(): IntrospectionSchema {
return HOST_FILESYSTEM
.source(this)
.buffer()
.toIntrospectionSchema(toString())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.apollographql.apollo3.graphql.ast.test.introspection
package test.introspection

import com.apollographql.apollo3.ast.SourceAwareException
import com.apollographql.apollo3.ast.introspection.toIntrospectionSchema
Expand All @@ -15,7 +15,7 @@ class IntrospectionTest {
@Test
fun parseSchema() {
try {
"${CWD}/src/commonTest/kotlin/com/apollographql/apollo3/graphql/ast/test/introspection/duplicate.json"
"${CWD}/src/filesystemTest/kotlin/test/introspection/duplicate.json"
.toPath()
.toGQLDocument(allowJson = true)
.toSchema()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.apollographql.apollo3.graphql.ast.test.validation
package test.validation

import com.apollographql.apollo3.ast.toGQLDocument
import com.apollographql.apollo3.ast.toSchema
Expand All @@ -12,12 +12,12 @@ import kotlin.test.assertNotNull
class OperationValidationTest {
@Test
fun deprecatedInputField() {
val schema = "${CWD}/src/commonTest/kotlin/com/apollographql/apollo3/graphql/ast/test/validation/inputTypeDeprecatedField.graphqls"
val schema = "${CWD}/src/filesystemTest/kotlin/test/validation/inputTypeDeprecatedField.graphqls"
.toPath()
.toGQLDocument()
.toSchema()

val operations = "${CWD}/src/commonTest/kotlin/com/apollographql/apollo3/graphql/ast/test/validation/inputTypeDeprecatedField.graphql"
val operations = "${CWD}/src/filesystemTest/kotlin/test/validation/inputTypeDeprecatedField.graphql"
.toPath()
.toGQLDocument()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.apollographql.apollo3.graphql.ast.test

internal actual val CWD: String
get() = TODO("Not yet implemented")
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public final class com/apollographql/apollo3/testing/MockserverKt {
public static synthetic fun enqueueData$default (Lcom/apollographql/apollo3/mockserver/MockServer;Ljava/util/Map;Lcom/apollographql/apollo3/api/CustomScalarAdapters;JIILjava/lang/Object;)V
}

public final class com/apollographql/apollo3/testing/ReadFileJvmKt {
public static final fun getHostFileSystem ()Lokio/FileSystem;
public final class com/apollographql/apollo3/testing/ReadFile_concurrentKt {
}

public final class com/apollographql/apollo3/testing/ReadFile_jvmKt {
public static final fun getTestsPath ()Ljava/lang/String;
public static final fun shouldUpdateTestFixtures ()Z
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.apollographql.apollo3.testing

actual fun shouldUpdateTestFixtures(): Boolean = false

actual val testsPath: String = "../"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.apollographql.apollo3.testing

import com.apollographql.apollo3.annotations.ApolloExperimental
import okio.FileSystem
import okio.SYSTEM

/**
* The host filesystem
*/
@ApolloExperimental
actual val HostFileSystem: FileSystem
get() = FileSystem.SYSTEM
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package com.apollographql.apollo3.testing

import okio.FileSystem
import okio.IOException
import okio.Path.Companion.toPath
import okio.buffer
import java.io.File
import java.io.FileNotFoundException

actual val HostFileSystem = FileSystem.SYSTEM

actual fun shouldUpdateTestFixtures(): Boolean {
if (System.getenv("updateTestFixtures") != null) {
return true
Expand Down
Loading